Docker COPY not updating files when rebuilding container

This is because of cache.

Run,

docker-compose build --no-cache

This will rebuild images without using any cache.

And then,

docker-compose -f docker-compose-staging.yml up -d

I was struggling with the fact that migrations were not detected nor done. Found this thread and noticed that the root cause was, indeed, files not being updated in the container. The force-recreate solution suggested above solved the problem for me, but I find it cumbersome to have to try to remember when to do it and when not. E.g. Vue related files seem to work just fine but Django related files don't.

So I figured why not try adjusting the Docker file to clean up the previous files before the copy:

RUN rm -rf path/to/your/app
COPY . path/to/your/app

Worked like a charm. Now it's part of the build and all you need is run the docker-compose up -d --build again. Files are up to date and you can run make migrations and migrate against your containers.


I had similar issue if not same while working on dotnet core application.

What I was trying to do was rebuild my application and get it update my docker image so that I can see my changes reflected in the containerized copy.

So I got going by removing the underlying image generated by docker-compose up using the command to get my changes reflected:

docker rmi *[imageId]*

I believe there should be support for this in docker-compose but this was enough for my need at the moment.