Docker for windows: pinging container from host

Hello guys.

Docker rookie here, so please be patient :slight_smile:

Ok, so I’ve installed docker for windows (Windows 10 Enterprise 1903 build 18362.30):

λ docker version
Client: Docker Engine - Community
Version: 19.03.2
API version: 1.40
Go version: go1.12.8
Git commit: 6a30dfc
Built: Thu Aug 29 05:26:49 2019
OS/Arch: windows/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.2
API version: 1.40 (minimum version 1.24)
Go version: go1.12.8
Git commit: 6a30dfc
Built: Thu Aug 29 05:39:49 2019
OS/Arch: windows/amd64
Experimental: false

I’ve set it up to use windows containers and I’ve pulled and run an image with IIS (nanoserver version):

λ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
microsoft/iis nanoserver d4d34a16ef9d 10 months ago 1.29GB

My container is up and running with the 81:80 port mapping:

λ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4116c7bc329c microsoft/iis:nanoserver “C:\ServiceMonitor.e…” 3 hours ago Up 21 minutes 0.0.0.0:81->80/tcp iis

Now, my problem is that I can’t ping the container from the host. I’ve used the inspect command to get the container’s IP Address:

λ docker inspect 6

“Networks”: {
“nat”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “bb2fb449d958ebe6662089b0fb2ea40c8f423d3480f6e5a5b8353cf14b0121af”,
“EndpointID”: “43362eaaaf4750e44abe98c9967795af316e79361b5914cd2e5ff5507d757946”,
“Gateway”: “172.31.176.1”,
“IPAddress”: “172.31.181.72”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “00:15:5d:55:69:ce”,
“DriverOpts”: null
}
}
}
}
]

Here’s the output of the ping command:

λ ping 172.31.181.72

Pinging 172.31.181.72 with 32 bytes of data:
Reply from 10.200.2.222: Destination net unreachable.
Reply from 10.200.2.222: Destination net unreachable.
Reply from 10.200.2.222: Destination net unreachable.
Reply from 10.200.2.222: Destination net unreachable.

Ping statistics for 172.31.181.72:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

I’ve tried running tracert and I’ve noticed that it’s being sent to the default gateway (instead of going to the docker’s nat):
λ tracert 172.31.181.72

Tracing route to 172.31.181.72 over a maximum of 30 hops

1 <1 ms <1 ms <1 ms 10.51.2.126
2 <1 ms <1 ms <1 ms 10.200.202.126
3 * * * Request timed out.
4 <1 ms <1 ms <1 ms 10.200.2.217
5 10.200.2.222 reports: Destination net unreachable.

Trace complete.

And here’s my routing table:
λ route print

Interface List
9…ac 22 0b 8a 3a 40 …Intel® 82579LM Gigabit Network Connection
12…00 19 86 00 3c 1b …Bluetooth Device (Personal Area Network)
1…Software Loopback Interface 1
15…00 15 5d db 0d fb …Hyper-V Virtual Ethernet Adapter
25…00 15 5d 55 61 52 …Hyper-V Virtual Ethernet Adapter #2

IPv4 Route Table

Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.51.2.126 10.51.2.7 281
10.51.2.0 255.255.255.128 On-link 10.51.2.7 281
10.51.2.7 255.255.255.255 On-link 10.51.2.7 281
10.51.2.127 255.255.255.255 On-link 10.51.2.7 281
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
127.255.255.255 255.255.255.255 On-link 127.0.0.1 331
172.17.71.224 255.255.255.240 On-link 172.17.71.225 5256
172.17.71.225 255.255.255.255 On-link 172.17.71.225 5256
172.17.71.239 255.255.255.255 On-link 172.17.71.225 5256
172.31.176.0 255.255.240.0 On-link 172.31.176.1 5256
172.31.176.1 255.255.255.255 On-link 172.31.176.1 5256
172.31.191.255 255.255.255.255 On-link 172.31.176.1 5256
224.0.0.0 240.0.0.0 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 10.51.2.7 281
224.0.0.0 240.0.0.0 On-link 172.17.71.225 5256
224.0.0.0 240.0.0.0 On-link 172.31.176.1 5256
255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
255.255.255.255 255.255.255.255 On-link 10.51.2.7 281
255.255.255.255 255.255.255.255 On-link 172.17.71.225 5256
255.255.255.255 255.255.255.255 On-link 172.31.176.1 5256

Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 10.51.2.126 Default

IPv6 Route Table

Active Routes:
If Metric Network Destination Gateway
1 331 ::1/128 On-link
9 281 fe80::/64 On-link
15 5256 fe80::/64 On-link
25 5256 fe80::/64 On-link
25 5256 fe80::203a:130f:411b:b8fa/128
On-link
15 5256 fe80::9164:82e9:9a09:4a13/128
On-link
9 281 fe80::c853:9e31:3cb3:d087/128
On-link
1 331 ff00::/8 On-link
9 281 ff00::/8 On-link
15 5256 ff00::/8 On-link
25 5256 ff00::/8 On-link

Persistent Routes:
None

I’m not a network guy, but it looks like everything is ok. I’ve tried installing docker for windows on another machine and everything works as expected without any additional configurations.

Any clues on what’s going on with this machine? Can anyone point me on the right direction?

Thanks.

Regards,
Luis

Ok, just adding more info…

After rebooting, the ips have changed, but I’ve also noticed something weird: the IP I get from the docker inspect container_id is different from the one I get on the machine.

λ docker inspect 6
“Networks”: {
“nat”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “11117ac2f84721d1ca93c719192dd4d2aa5f9e6d23e7b3077dfd8ffb63aaf2e2”,
“EndpointID”: “c7eac036cb3037b092a28cb8d1b6cb532c388192f6410361665c950fcaad48c5”,
“Gateway”: “172.23.160.1”,
“IPAddress”: “172.23.175.99”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “00:15:5d:33:8c:be”,
“DriverOpts”: null
}
}

λ docker exec -it 6 powershell
Windows PowerShell
Copyright © 2016 Microsoft Corporation. All rights reserved.

PS C:> ipconfig

Windows IP Configuration

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . : mshome.net
Link-local IPv6 Address . . . . . : fe80::19e6:caeb:2e4c:32d5%4
IPv4 Address. . . . . . . . . . . : 192.168.238.61
Subnet Mask . . . . . . . . . . . : 255.255.255.240
Default Gateway . . . . . . . . . : 172.23.160.1
192.168.238.49
PS C:>

Any ideas on what’s going on here?

Hello again.

After playing a little more with it, I’ve went with the docker network prune (which deleted the default switch) and now everything seems to be working fine…