Gunicorn Flask application in Docker Container not getting Exposed Gunicorn Flask application in Docker Container not getting Exposed flask flask

Gunicorn Flask application in Docker Container not getting Exposed


By default, 127.0.0.1 means a different thing inside the container than it does outside. Use 0.0.0.0:5000 instead.


To expand on the other answer: the way Docker port forwarding works is to forward from the IPs on the host machine to one address in the container. Specifically, the external address that talks to the Docker bridge network that connects the container to the host network. It can't talk to to 127.0.0.1 on the container because that's a private IP—the host has its own 127.0.0.1.

So you need to either bind to that Docker bridge network, or just bind to all interfaces by binding to 0.0.0.0, which is the easiest solution.

Explaining this with prose is a little tricky, but I have longer version that also includes diagrams and will probably therefore be easier to understand: https://pythonspeed.com/articles/docker-connection-refused/


Try this command in your Dockerfile:

CMD ["flask", "run", "--host=0.0.0.0"]