skip to Main Content

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


  1. 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:

    ...
    
    VOLUME ["/app"]
    WORKDIR /app
    COPY . /app
    EXPOSE 80:80
    ENV FLASK_APP=app.py
    CMD ["flask", "run", "--host", "0.0.0.0", "-p", "80"]
    

    My docker-compose.yaml:

    version: "3"
    services:
      app:
        build: .
        ports:
          - "80:80"
        volumes:
          - ./:/app
        environment:
          # if set to 1 the changes will be propagated instantly
          FLASK_DEBUG: 1
    

    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.

    Login or Signup to reply.
  2. Docker tags should ideally be immutable. If you’re just using docker run <image> rather than docker run <image>:<new tag>, then you’re just running the previously pulled, locally cached latest tag. Running an image doesn’t automatically pull the newest latest tag

    Also, as commented, your browser can cache static web assets

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search