macOS port mapping connection refused

I’ve followed the steps provided in the lesson https://kodekloud.com/courses/296044/lectures/4554709 and when I run docker run -p 80:5000 some-name the Flask app runs but I get a “The connection was reset” in Firefox. I’m on macOS 10.15.4.

https://hub.docker.com/repository/docker/ricardoaugusto/simple-flask-app

Why is that?

Hi ricardoaugusto,

Check the example below for 20. Demo to know what you have missed.

Also, the docker host IP is the IP of the machine itself and you can get it using the command ifconfig

There are two ways to access the application :

  1. Without port mapping, you can access your application using http://172.17.0.2:5000. But for this, you need to be able to access the IP 172.17.0.2. This IP is an IP assigned to the docker container by the docker host. So you must be inside your Docker host (which I believe is a Linux VM in your case). If your Linux VM doesn’t have a GUI, then you can try accessing your application using curl like this: curl http://172.17.0.2:8080/hello

  2. With Port Mapping - To access your application outside the Docker host, you need to map the port on the docker container (172.17.0.2:5000) to a port on the Docker host (192.168.10.100:5000). Because, from outside of your docker host, like your laptop, you can only ping the Docker host and not the docker container directly.

This is explained in detail in Demo - Docker run here