Can't access publicly exposed Docker container port from external machine, only from localhost? Can't access publicly exposed Docker container port from external machine, only from localhost? linux linux

Can't access publicly exposed Docker container port from external machine, only from localhost?


You didn't publicly publish your port with this flag:

-p 127.0.0.1:7091:7091

That flag says to publish on the host 127.0.0.1 interface (localhost), port 7091 to the containers port 7091. The only way to reach that port is to be on the host and connect to the loopback interface.

To publicly publish the port, remove the IP from that flag:

-p 7091:7091

or explicitly publish to all interfaces with:

-p 0.0.0.0:7091:7091

The latter format is identical to the first one as long as you haven't overridden your docker daemon settings with dockerd --ip x.x.x.x or setting the ip value in your /etc/docker/daemon.json file.


I don't think the container's IP is 192.5.169.50. Try doing docker inspect <container-uid> | grep IPAddress to check what the IP of the container is. I believe it should be something like 172.17.0.X.

Also you could just do docker run -d --network=host <image> which stacks the container on top of the host network.

Container are just something on top of the host, the host is the one that is actually communicating with the outside.