Docker Community Forums

Share and learn in the Docker community.

Access service on host machine from docker container


(Paulfrench) #1

I can’t seem to find a well documented answer…

I have a docker container and I have a service running on the host machine (in this case cvs). From my docker container I cannot access the cvs service.

I can “docker exec /bin/bash” into my container and ping the host and it pings the host fine with the correct IP address. However when my docker container tries to connect to CVS I get the error:

ERROR: CVS Authentication failed: NoRouteToHostException

I’m running on CentOS 7.4 and I have disabled the local firewall.

If I was accessing the CVS service on a different machine it would work fine. Just because the CVS service is running on the same host as docker it does not work.

What do I need to do? Any ideas appreciated?

(Paulfrench) #2

I’m bumping this since it is still an issue.

(Sam) #3

what address is the cvs app using to connect back to the host?
if you docker attach container_id to the container, can you manually issue the cvs commands?

(Paulfrench) #4

My environment has moved on. However I have a http service running on the host. From a docker container I cannot access the host service. From the container…

ping <my-host-name> - works and <my-host-name> resolves to the external IP of the host

curl http://<my-host-name>:8080/ - does not work I get "curl: (7) Failed connect to <my-host-name>:8080; No route to host

Like I said before, if I run the container on a different host and run curl I don’t have a problem.

(Sam) #5

Can you try the host ip address on the curl instead of the hostname? Is the host Windows?

(Paulfrench) #6

Same error:

curl: (7) Failed connect to xx.xx.xx.xx:8080; No route to host

Host is centos 7.4

(Paulfrench) #7

At the moment any container that needs to access a host service I have to run in network mode “host” which is a real pain, especially if I want to run multiple containers of the same image (i.e. it is not possible)

(Sam) #8

So, how can ping work?

(Paulfrench) #9

Good question, but it does!

(Paulfrench) #10

Apologies. I got a test case ready to demo the issue and tested it on the VM and it showed the problem.I re-run the test on another VM and it was fine. So I rechecked the problematic VM and low and behold the firewall was switched on. Someone in my office had restarted it after I disabled it. I do feel stupid!

Thanks for your help anyway, it got me to re-look at the issue in more detail.

Word of warning though. Once I stopped and disabled firewalld I couldno longer create containers due to a docker network error. I had to restart docker as well and then all was fine again,

(Sam) #11

oh the joys of other people doing things!.. thanks for the update