I can't ping my container in the default network

Hello, Im trying to run a minecraft server inside a container. After running the container I try to connect through it game, but the server doesn’t answer.
I noticed I can’t ping the container

$ ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
^C
--- 172.17.0.2 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1036ms

I also can’t ping the gateway of the default network.

 ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
^C
--- 172.17.0.1 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2040ms

But I can ping from inside the container to the internet.

$ docker exec -it e163463ac9c5 bash
root@e163463ac9c5:/# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=254 time=87.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=254 time=315 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=254 time=338 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3004ms
rtt min/avg/max/mdev = 87.340/246.785/337.547/113.104 ms

It also doesn’t work if I create a new network.
How can I fix this? Thanks
I’m on ubuntu 22.

1 Like

Hello.

If you want to communicate with the container from outside to inside, please consider port forwarding of the container and host environment.

Of course, it is impossible to ping the inner container ip from the outside.

1 Like