1

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.

paul
  • 494
  • 6
  • 17
  • can you `curl` on port 1234 host B from host A when container A is running on B ? – Ngob Jan 26 '18 at 09:45
  • I think you should try matching the final IP address via which you are trying to connect because sometime 192.168.10.1 is not same as 127.0.0.1 – Prateek Jain Jan 26 '18 at 09:58
  • Benoit - yes I can – paul Jan 26 '18 at 11:17
  • techtrainer - the service on host B is listening on all interfaces. I can use 192.168.10.X externally or 127.0.0.1 (if on host B) – paul Jan 26 '18 at 11:19

1 Answers1

1

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

opHASnoNAME
  • 20,224
  • 26
  • 98
  • 143
  • Does not work, same issue. Plus I now have to reference hostname "db" instead of it's well known hostname. I also have to work out the IP of the interface in the container that is the host. I still get "no route to host". For now I have started the container with network mode "host", a bodge but it works. – paul Jan 26 '18 at 16:04