I am investigating an issue, that I can not connect to docker containers via exposed ports to 80 or 8080 on a newly installed Linux Ubuntu 22 machine. Instead, every request hangs.
So I rebooted the machine and stopped all services like nginx and docker. Nothing is listening on specific ports.
curl http://0.0.0.0:8000
:
as expected, it prints
curl: (7) Failed to connect to 0.0.0.0 port 8000 after 0 ms: Connection refused
However, curl http://localhost:8000
causes curl to hang forever.
When I do ping localhost
, it shows it resolves to 127.0.0.1 (as expected)
And curl http://127.0.0.1:8000
also failes to connect:
curl: (7) Failed to connect to 127.0.0.1 port 8000 after 0 ms: Connection refused
netstat -l -p
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN -
tcp 0 0 localhost:domain 0.0.0.0:* LISTEN -
tcp6 0 0 [::]:ssh [::]:* LISTEN -
udp 0 0 localhost:domain 0.0.0.0:* -
udp 0 0 Ubuntu-2204-jammy-a:ntp 0.0.0.0:* -
udp 0 0 localhost.localdoma:ntp 0.0.0.0:* -
udp 0 0 0.0.0.0:ntp 0.0.0.0:* -
udp6 0 0 Ubuntu-2204-jammy-a:ntp [::]:* -
udp6 0 0 Ubuntu-2204-jammy-a:ntp [::]:* -
udp6 0 0 [::]:ntp [::]:* -
raw6 0 0 [::]:ipv6-icmp [::]:* 7 -
What could this be?
I can answer by myself. As pointed out by helpful people on my Reddit-thread, it is due to iptables
.
As soon as iptables is acticated, things are going not well for docker.
I found a blogpost that describes, what needs to be done in order to setup iptables in conjunction with docker:
https://blog.jarrousse.org/2023/03/18/how-to-use-ufw-firewall-with-docker-containers/