I've run into a frustrating issue with Docker networking on my Linux VM and could use some help. I'm trying to expose Docker container ports to my local network, and while low ports like 80 and 8080 work perfectly, I can't seem to get high ports (like 40200) to connect. The failure happens outside the VM—when I try to telnet into the high port from another device on the same LAN, I get an immediate 'Connection refused' error. Inside the VM, everything works fine, including a listener setup with netcat on that high port. I've tried disabling firewalls and confirmed that IP forwarding is enabled, yet the problem persists only with Docker's port forwarding for high ports. Why is this happening?
2 Answers
It sounds like you might be overlooking an important detail in your port mapping. Typically, when mapping ports, you'd want to only change the host-side port. For example, instead of changing both to 43200, you should stick to something like `43200:1000` if the container is actually listening on port 1000. If there's an issue with your iptables setup, try running `iptables -L` to check your rules.
Are you sure you want to map the container's high port directly to a high port on your VM? You could try running a basic OS image as a container and then mapping a port, running netcat inside that container to ensure everything's set up right.
That's exactly what I usually do—having nc run inside a service wrapper helps debug port issues like this!