Reputation: 8968
I run: docker run -p "9999:80" nginx
and attempt to access the web server using the following address: 172.17.0.2:9999
. I got this IP from docker inspect [container_id]
:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "877eb750a0f35037f0b9dff2b6bd95f7dd4aaf80ae0ed8cf65e20ad8aeb85132",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9999"
}
]
},
"SandboxKey": "/var/run/docker/netns/877eb750a0f3",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "2599dc8c2311725e9816fc30e60a86550cb42887871a921365e3df866427464e",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "ffc037f862047b118824b8d322aab771ba75a009881959461be577ffebb42a80",
"EndpointID": "2599dc8c2311725e9816fc30e60a86550cb42887871a921365e3df866427464e",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
But this doesn't work as expected. If I ping 172.17.0.2
from the host I get no response.
Any ideas what's going wrong? It's so much hassle with docker-toolbox
because my version of Windows 10 isn't supported by docker.
Upvotes: 1
Views: 925
Reputation: 159875
Since you launched the container with docker run -p 9999:80
, you can reach it on the VM's IP address on the public port 9999. docker-machine ip
will tell you that IP address (but it is usually 192.168.99.100). So try http://192.168.99.100:9999/
as a URL to reach the container.
The container-internal IP addresses aren't especially useful. One significant problem with them is that they can't be reached from other hosts. In the case of a Docker Toolbox environment, everything Docker-related actually runs inside a virtual machine, and your host system counts as "other hosts" for this. Also note that if you do have occasion to use it (or more often use inter-container DNS for one container to reach another by its docker run --name
) you need the port the server is listening on inside the container, not the published port: from another container you might use http://nginx_container_name:80/
.
Upvotes: 3