Cannot access container server with --net=host

I’m a newbie so go easy on me. I have a container created with --net=host. I am running python3 -m http.server 8080 inside. lsof -i shows this …

python3  29 root    3u  IPv4 1410584      0t0  TCP *:8080 (LISTEN)

When I run curl http://127.0.0.1:8080 inside it works. But when I run that command outside I get …

curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

Shouldn’t this work? If not what should I use outside to get access to a port inside?

Hi, and welcome :slight_smile:

127.0.0.1 aka “local host”, is the machine itself, os that works because you’re running the command from the same host as the docker is running.

So if you want to access it from another pc/host, you need to access it via the real ip or hostname of that server, fx. http://192.168… (or whatever your local ip adresses is) :slight_smile:

Thanks. I have been trying to access it from everywhere. I have tried all three ips from three places for nine total. The thre ips are 0.0.0.0, 127.0.0.1, and 192.168.1.103. The three locations are inside docker on the server, outside docker on the server, and from a client pc. The only ones that work are ones used inside docker with curl. I am not able to access the server in the container from the outside.

My guess is that you use Docker Desktop. That will not work. You need port forward.

See https://learn-docker.it-sziget.hu/en/latest/pages/advanced/kernel-namespaces-network.html#running-a-web-browser-in-a-net-namespace-in-a-vm-docker-desktop

This slide can illustrate how you have three localhosts and the host network will mean the host of the virtual machine.

I fixed it the hard way :slight_smile: I upgraded my linux server from ubuntu 18 to 20. This gave me a pretty fresh system. At reboot docker was already running and working.

Thanks to all for the help.

hi @mchahn can you explain more, I have same problem when install GitHub - tiredofit/docker-freepbx: Dockerized FreePBX 15 w/Asterisk 17, Seperate MySQL Database support, and Data Persistence and UCP inside docker ( with --net=host), hence I can not open localhost:80