Trying to connect to a dockerized Flask app fails with error 104, 'Connection reset by peer' using this minimal example:


from flask import Flask
app = Flask(__name__)

def hello():
    return "Hello World!"

if __name__ == "__main__":


FROM python:alpine
RUN pip install flask
COPY . /src/
ENTRYPOINT ["python", "/src/app.py"]


    build: .

Flask app seems to be running as expected:

$ docker logs test 
 * Running on (Press CTRL+C to quit)

Trying to connect from outside fails:

$ http
http: error: ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) while doing GET request to URL:

Any ideas, why I can't get to see "Hello World!" here?

1 Answer 1


Trying to connect from outside fails

Are you actually connecting from outside? Flask is binding to localhost ( and that will only be reachable from within the container. If you're on your local machine, you'll need flask to bind to all IP's:

from flask import Flask
app = Flask(__name__)

def hello():
    return "Hello World!"

if __name__ == "__main__":

That works for me successfully.

  • 1
    Thats right. Never thought this is actually a python or flask problem, as I just copied it from the docs. Thx
    – mcnesium
    Commented Feb 20, 2018 at 18:00
  • Or with gunicorn: gunicorn --bind app:app Commented Apr 15, 2019 at 7:18
  • 2
    If you're using flask run, use --host= Or in the Dockerfile: CMD ["flask", "run", "--host="]
    – sebas
    Commented Sep 7, 2019 at 10:46
  • I have been looking for this for 4 days >D lol Commented Nov 19, 2019 at 12:50
  • +1 You saved my day :) So happy to find this answer after 20 min and not 4 days
    – lanenok
    Commented Sep 2, 2020 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.