Restart flask app in docker on changes

一世执手 提交于 2019-12-03 22:41:57
R0MANARMY

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!