Restart flask app in docker on changes Restart flask app in docker on changes flask flask

Restart flask app in docker on changes


The COPY instruction

copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.

That means the image has a snapshot of the files as they were when the image was built. When you start a container from that image, it will see the copy of your files in its file system. Modifying the original files will not have any effect on the copies inside the container, the app doesn't see those changes and doesn't restart.


If you want the files to change inside the container, you can mount a host directory as a volume. Also from the docs

This command mounts the host directory, /src/webapp, into the container at /webapp. If the path /webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content. Once the mount is removed, the content is accessible again.

The Docker run command will probably look something like this

docker run -d -v /absolute/path/to/src:/app <image-name>

Then your file changes should be reflected in the files inside the container (because they will be the same files) and everything should restart as expected.


You may also be interested in this post Dockerize a Flask, Celery, and Redis Application with Docker Compose. It takes it one step further and uses Docker Compose to orchestrate a Flask development environment.