Access service on host machine from docker contain

2019-07-28 07:27发布

I've asked a similar question on the docker forum...

https://forums.docker.com/t/access-service-on-host-machine-from-docker-container/45117

...but I'm not getting any joy and this should not be difficult. However when I google about it seems that it is difficult which seems crazy to me. So I'll ask the question in a different way...

Host A running docker container A

Host B running a legacy service exposed on port 1234

container A can access the legacy service on host B on port 1234 (no problems)

Now I decide to run container A on host B. The crazy thing is container A can no longer access the legacy service provided by host B no matter what I try!

There must be a way to do this reliably?

Container A can ping host B fine when running on host A or B but when container A tries to connect to the legacy service I always get the error

No route to host

There is no firewalls (they have been disabled) and dns works fine within container A and resolves host B to the correct IP no matter what host it is running on.

标签: docker
1条回答
放我归山
2楼-- · 2019-07-28 08:02

Think you have to pass the HOST to the Container when running on the same Host. For example Wordpress with "legacy" DB on Host B.

docker run --name wordpress --add-host=db:172.17.0.74 

Now you can point Wordpress to DB Host: db

查看更多
登录 后发表回答