Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python: Cant expose flask app in docker container

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading