I have a flask project, usually i push it to dockerhub and i run it using docker run dockerhub-image
, and after i updated things inside static folder, i stopped and removed the container and also removed the image, after that i repush it again to dockerhub and re-run it, but when visiting it on the web, the files inside static folder does not change at all (other files outside static folder are changed), had no idea to fix this.
I have searched questions related to this issue but couldn’t find any of it.
Q: how do fix this issue?
2
Answers
In my case, I had trouble getting changes to my Flask app to propagate to my Docker container, even when using volumes. After some experimentation, I found a solution that worked for me.
First, I modified my Dockerfile to include a VOLUME instruction that specifies the root directory of my app as a volume. My Dockerfile:
My docker-compose.yaml:
Both my Dockerfile and docker-compose.yaml are located under the project root folder
app/
I also set the FLASK_DEBUG environment variable to 1 in docker-compose.yaml to see the code changes while developing.
So what worked for me is 1) adding the complete app directory as a volume. See documentation. 2) Setting debug mode to true in docker-compose.yaml
I also want to give credits to this article which I partially got the solution from.
Docker tags should ideally be immutable. If you’re just using
docker run <image>
rather thandocker run <image>:<new tag>
, then you’re just running the previously pulled, locally cachedlatest
tag. Running an image doesn’t automatically pull the newestlatest
tagAlso, as commented, your browser can cache static web assets