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 inside it works. But when I run that command outside I get …

curl: (7) Failed to connect to 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: 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,, and 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.


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.