Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker refused to connect

After I docker-compose build and docker-compose up, if I go to localhost:5000 in my browser (Which is the port I exposed in the yml file), I get:

This site can’t be reached. localhost refused to connect.

However, if I go to 192.168.99.100:5000, the container loads. Is there a way I can fix this issue?

like image 507
AspiringMat Avatar asked Sep 18 '25 16:09

AspiringMat


1 Answers

Bind your container port to 127.0.0.1:5000.

By default, if you don't specify an interface on port mapping, Docker bind that port to all available interfaces (0.0.0.0). If you want to bind a port only for localhost interface (127.0.0.1), you have to specify this interface on port binding.

Docker

docker run ... -p 127.0.0.1:5000:5000 ...

Docker Compose

ports:
 - "127.0.0.1:5000:5000"

For further information, check Docker docs: https://docs.docker.com/engine/userguide/networking/default_network/binding/

like image 61
kstromeiraos Avatar answered Sep 20 '25 10:09

kstromeiraos