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?
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With