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
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:
netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With