Connecting to containers IP address

Expected behavior

IP address of container will be available to host for connection

Actual behavior

Cannot access, no route to host

Information

By default dockerNAT assigns 10.0.75.0/24 to MobyLinuxVM.
Docker inside MobyLinuxVM assigns to containers IP addresses in range 172.17.0.0/16. You have to alter route tables to access containers IP address:

route add  172.17.0.0 MASK 255.255.0.0 10.0.75.2

Steps to reproduce the behavior

  1. create container
  2. discover containers IP address
  3. ups … cannot ping that address
1 Like

Thanks for reporting. We’re aware of these limitations and are working on improvements.

Is this still a problem? I seem to also have this issue but the “route add” doesn’t fix it for me.

1 Like

In fact I have a completely opposite problem.
I started a SQL Server 2016 express container and the SQL Server instance is visible and accessible from all the machine s except the host machine.
I tries all the combinations of hostname\SQLexpress but to no avail.
Then I found out the conatiner address and tried connecting to it and it worked.
Still confused. though.

You might want to check out this: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/

I think this is related question (or the same) Access container from dev machine (by ip/dns name)

Does it have some relation to Original question?

route /P add 172.0.0.0 MASK 255.0.0.0 10.0.75.2

works for me, I can now access 172.x.x.x from dev machine

1 Like

route add 172.17.0.0 MASK 255.255.0.0 10.0.75.2

works too, the -p is for persistence

It won’t work in the latest version.

route add does not resolve in my situation.
I can ping gateway 172.17.0.1 but not container 172.17.0.3.
Docker for windows version: 17.12.0-ce

@abdujaparov Same to me !

Is this fix just for VMs? I have this issue connecting to Linux containers using the python:slim-buster image for flask applications. I can browse webpages hosted on containers prior to bringing my containers up with docker-compose. After they’re connected to the 172.17.X.X network, adding routes does not solve problem.

I have tried different combinations for gateway IP including container IP and actual gateway of docker-compose network.

In order to make it work your VM should act as a router and the VM’s IP address should be visible from Windows. In the recent Docker Desktop versions it does not seem to be the case.

If you want to access the services, you need to forward ports (docker run -p 8080:80 ...)
If you just want to test if a service is listening on the proper internal IP address, you can try this:

docker run --rm -it --net host nicolaka/netshoot wget -O- http://172.17.0.2