Windows docker container cannot ping host
Asked Answered
C

6

7

I am running a windows docker container on a Windows Server 2016 host, running default configuration.

When running the docker container using the command:

docker run -it microsoft/windowsservercore powershell

When I run the command:

ping <hostIPAddress>

It just says that the request times out. I have checked that I can ping 8.8.8.8 and google.com etc... and even other machines on the same subnet. The only one I cannot ping is the host.

I have added '--dns ' to the 'docker run' command but this only allows me to ping the host machine via hostname and not IP.

Has anyone else seen this problem and have a solution?

Cheyennecheyne answered 28/3, 2017 at 16:7 Comment(3)
I'm facing the same issue right now, have you found a solution by any chance?Nessie
Still no solution I am afraidCheyennecheyne
Couple of month later. Does anyone have a solution for this yet. I've seen that a few folks are abandoning the whole NAT ideaLoeb
N
5

I found a workaround (I'm not willing to call it a solution):

Windows Container Network Drivers: create a 'transparent' network:

docker network create -d transparent trans

Attach container to this network

docker run --network=trans ...

Important: Please note, that with this network, your container needs to obtain an IP Adress from the Host Subnet and it is directly exposed to it.

maybe related (this is about access the containers from the host):

According to https://github.com/Microsoft/Virtualization-Documentation/issues/253#issuecomment-217975932 (JMesser81):

This is a known limitation in our Windows NAT implementation (WinNAT) that you cannot access the external port in a static port mapping directly from the container (NAT) host.

Nessie answered 18/5, 2017 at 14:5 Comment(0)
B
1

In my case I have a corporate managed McAfee firewall running on my Windows host. I could not add any additional rules on the firewall, but fortunately there was a rule that allowed access from 172.16.0.0/24.

I used "docker network create -d transparent trans" and it worked as described, but I was not happy with an IP from my host network assigned to the container.

I did the following:

  • docker network create --driver=nat --subnet=172.16.0.0/24 br0
  • Added --network=br0 to my docker run command
Bead answered 2/1, 2020 at 17:19 Comment(0)
B
1

Hoping this might help somebody.

On Windows 10 when hosting a Linux container on 0.0.0.0:5057 I was able to ping my server from my Windows host (powershell) using the IP address of the vEthernet (Default Switch) NIC found in Control Panel>All Control Panel Items>Network Connections:

Win10 host IP of Linux Container

Bhakti answered 17/4, 2020 at 13:31 Comment(1)
Original question was how to ping host from Docker container, not how to ping container from the host.Propose
I
0

I am facing the same issue.

My workaround is to restart docker service, afterwards it works fine. I'm still looking for a permanent solution.

root@a6c40eb25cbf:/# ping xxx.xx.xx.xxx
PING xxx.xx.xx.xxx (xxx.xx.xx.xxx): 56 data bytes
64 bytes from xxx.xx.xx.xxx: icmp_seq=0 ttl=37 time=3.541 ms
64 bytes from xxx.xx.xx.xxx: icmp_seq=1 ttl=37 time=2.643 ms
64 bytes from xxx.xx.xx.xxx: icmp_seq=2 ttl=37 time=1.857 ms
^C--- xxx.xx.xx.xxx ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
Intersexual answered 20/1, 2018 at 5:6 Comment(0)
C
0

This works for me, I hope it works for you.

Currently, you must have WSL or WSL2 installed and have Virtualization enabled to run Docker on Windows. The installation of WSL from PowerShell is with the following command.

wsl --install -d Ubuntu

Obviously you need to download and install Docker Desktop on Windows. It will be necessary to enable the WSL integration from the Docker desktop settings after installing it.

enter image description here

After configuring WSL and Docker Desktop, you can create/use your containers. Example:

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres

Finally you must identify the IP of WSL, you must open the Linux distribution that you installed in the first step, in our case Ubuntu, this will open your terminal and here we will execute:

ifconfig

and you will identify the ip of eth0. Example: 172.27.123.123

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 172.27.123.123  netmask 255.255.240.0  broadcast 172.27.127.255
    inet6 fe80::215:5dff:fecf:b4  prefixlen 64  scopeid 0x20<link>
    ether 00:15:5d:cf:00:b4  txqueuelen 1000  (Ethernet)
    RX packets 4389  bytes 299784 (299.7 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 4343  bytes 315643 (315.6 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Now you can ping from CMD in Windows to this IP.

NOTE: the connection will depend on the port of your container, example: 172.27.123.123:8080.

Colvert answered 16/10, 2022 at 7:18 Comment(0)
P
0

I recently faced this problem while trying to use Xdebug with Docker and WSL2. I tried everything from changing VSCode/Xdebug settings, disabling firewalls, and various internet/network troubleshooting steps, but nothing seemed to fix it or suggest any reason why my Docker container couldn't access my WSL2 host IP.

Finally, in desperation I uninstalled Docker and reinstalled it and voilà---Xdebug magically works again! So if all else fails, try reinstalling Docker Desktop.

Propose answered 3/11, 2023 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.