I have a Flask app that works localy but i cant get it to work running in a docker container.
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.
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')


