14

I have a docker daemon started in the host machine listen to some ip address and port, say 10.10.10.10, and port 1234, then I start a container by invoking

sudo docker -H 10.10.10.10:1234 centos /bin/bash

Meanwhile, I have a web service runnig on the host machine, running on the port 8080. Then from inside the container, I cannot connect to this server. I tried

curl http://10.10.10.10:8080

but got an error message:

curl: (7) couldn't connect to host

But I can access the server in other machines, like http://10.10.10.11:8080 It seems that docker container cannot access the service in its own host machine? Is there anyway to fix this? Thanks

yuan
  • 1,113
  • 2
  • 9
  • 10
  • 1
    See http://stackoverflow.com/questions/27556301/connect-to-local-mysql-server-through-docker/27564532#27564532 – Bryan Apr 13 '15 at 09:50

1 Answers1

7

That was discussed in issue 1143 and there might be one day a --link-host option.

In the meantime, the blog post "Accessing the Docker Host Server Within a Container" lists a few option:

  • The Gateway Approach: netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'
  • The IP Approach: boot2docker ip address is 192.168.59.103.

Although there’s no way to introspect the host’s ip address (AFAIK) you can pass this in via an environment variable:

docker@boot2docker:~$  docker run -i -t -e DOCKER_HOST=192.168.59.103 ubuntu /bin/bash
root@07561b0607f4:/# env
HOSTNAME=07561b0607f4
DOCKER_HOST=192.168.59.103

You have other options in "Network Configuration", with the virtual interface named docker0 on the host machine.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250