Search code examples
dockerdocker-composedocker-volume

Recreate named volume with compose


-V, --renew-anon-volumes   Recreate anonymous volumes instead of retrieving
                               data from the previous containers.

Does docker-compose up -V not apply to named volumes?

I have a service that, at image build time, pulls some files from SVN. It then creates a named volume. I can docker-compose build --no-cache to recreate the image and pull latest files from SVN. But the volume doesn't get updated on docker-compose up -V, unless I remove it beforehand.

I just want a clean and simple way to update files in a named volume

Sure, I could manually remove the volume, and then run everything, but I really wanted it to be compose-driven. This leads me to a second problem.

There is a docker-compose down -v that will also remove volumes, but I cannot run that against a single service (only all or nothing).

So I need to somehow figure out the named volumes of just 1 service from compose-file, and then use some extra command (docker volume rm?) to remove just that one volume.


Solution

  • If you don't care about the content of a named volume, either don't create it in the first place (remove the named volume line in the compose file) or delete it when you stop the project with:

    docker-compose down -v