How to fix hot-reload problem on a Flask application inside Docker?
I want my flask application to run with hot reload inside docker container but if I change my app.py flask application to app.run(debug=True,host='0.0.0.0')
instead of False
, it raises the error:
FileNotFoundError: [Errno 2] No such file or directory: ‘/app/app.py’: ‘/app/app.py’
If I change back to False
:
app.run(debug=False,host='0.0.0.0')
it will run, but without hot reload.
My Dockerfile is:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python3-pip python3-dev build-essential locales
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE pt_BR:pt:en
ENV LC_ALL en_US.UTF-8
ENV FLASK_ENV="development"
WORKDIR /app
COPY . /app
VOLUME ["/app"]
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python3"]
CMD ["app.py"]
and I run it using the command:
docker run -p 5000:5000 -v /Users/rodrigodmpa/Documents/IA/web:/app flask-app
Source: StackOverflow