Docker Flask, stuck at "Waiting response from localhost" Docker Flask, stuck at "Waiting response from localhost" flask flask

Docker Flask, stuck at "Waiting response from localhost"


Ok so I had that same issue during an interview a bit more than a year ago and it still puzzles me to this day.

I don't know why it's not working as expected when running the flask app with app.run().

Somehow it works fine when starting the app with the flask command line directly.

The Dockerfile would look like this:

FROM python:2.7COPY . /pywebWORKDIR /pywebRUN pip install flaskENV FLASK_APP=app.pyCMD ["flask", "run", "--host", "0.0.0.0"]

And you can drop app.run(host='0.0.0.0') from the __init__.py file.

I'll probably spend some time later trying to understand why your original implementation doesn't work as expected. I don't know much about flask but I don't see anything wrong in your code.


You should mention the port in flask app and set debug = True

app.run(host='0.0.0.0', port=5000, debug = True)

You should connect to the same port

docker run -p 3000:5000

Now you can access your app at http://localhost:3000/


This might not answer the OP's question but might answer others' questions who came here..

For me, the Flask output showed that the application was running after launching the Docker container. It showed this line, for example:

Running on http://172.17.0.2:5000/ (Press CTRL+C to quit)

So, I clicked this link and expected it to work.

However, you need to connect to the Docker container --- not the Flask app. Going to http://172.17.0.2:5000/ connects to the Flask app directly, which won't work. You need to go to http://0.0.0.0:5000/, which connects to the Docker container, which connects to the Flask app.

So going to http://0.0.0.0:5000/ worked.