How I Wasted 3 Hours Because Docker Ports Weren't Open (Solved)
To cut to the chase, it was a firewall and binding address issue. I'm leaving the trial-and-error process here.
Yesterday I deployed a container on our internal test server, but it wasn't accessible from outside. It worked fine locally, but as soon as I put it on the server it went quiet like it was dead. No logs either.
At first I thought it was an app issue and dug through the code, but it turned out 1) the container was bound to 127.0.0.1 and 2) the port was blocked by the server firewall. The two overlapped, which made it even more confusing.
- In docker-compose, specify the host address like ports: "8080:8080", or
- Check 0.0.0.0 binding
- Check the firewall with ufw status
If you check in this order, you'll catch most cases. I'm writing this down in case someone else runs into the same thing.
4 answers
Well, that's a bit... If it took 3 hours, isn't that still pretty fast to figure out? And if the conclusion was that it was the firewall, then the title "docker port not opening" is a bit misleading from the start. It wasn't a container issue but a server configuration issue, right? People searching for this would get confused.
Binding to 0.0.0.0—this is something everyone runs into at least once as a beginner lol. Back in the day, I was just staring at the code, then checked the port mapping again with docker ps and finally found it. But also check whether ufw keeps its settings after a reboot. Sometimes it resets, and something that was working gets blocked again.