-1

I have a Flask app that works localy but i cant get it to work running in a docker container.

Structure of the project:

Tree structure of the project

Contents of the Dockerfile:

FROM python:3.9

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code

COPY Pipfile Pipfile.lock /code/
RUN pip install --upgrade pip
RUN pip install pipenv && pipenv install --skip-lock --system

COPY . /code/

CMD ["python3", "./run.py"]

this are the comands i use to build and run the image

docker build --tag time-managment .
docker run -p 5000:5000 time-managment

And the container semms to run fine.

Docker ps: docker ps

FLask message: FLask running

But i cant acces it with my browser i just get a "This page does not work" message, no uptades on the logs or anything.

What am i doing Wrong?

  • `http://localhost:5000`? What status code does it return? Is your Flask app has a handler bound to the `/` path? – Zazaeil Jan 16 '22 at 18:39
  • i just get a ERR_EMPTY_RESPONSE, and yes the app has a handler boud to the / path – Santiago Torres Jan 16 '22 at 18:42
  • You can't "just get". HTTP protocol always returns an error. Somehow I think you get 204 No Content. Open your Network tab in the browser and carefully learn the request<>response details. – Zazaeil Jan 16 '22 at 18:43

1 Answers1

1

In the logs, you can see Running on http://127.0.0.1:5000/ (Press CTRL+C to quit). 127.0.0.1 means that your app is 'bound' to 127.0.0.1 (localhost) which means that it'll only accept connections from that machine. In a Docker container, localhost is the container itself. So it won't accept connections from outside the container.

To get it to do that, you need to make it bind to 0.0.0.0 instead. Then it'll accept connections from anywhere.

You do that by adding the host parameter to your app.run statement in your program, like this

app.run(host='0.0.0.0')
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35