Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 349
Slav Avatar asked Mar 24 '20 18:03

Slav


People also ask

How do I force recreate Docker compose?

If you want to force Compose to stop and recreate all containers, use the --force-recreate flag. If the process encounters an error, the exit code for this command is 1 . If the process is interrupted using SIGINT (ctrl + C) or SIGTERM , the containers are stopped, and the exit code is 0 .

Can Docker compose create volumes?

We can also create a volume with Docker compose service or also specify existing volumes. For example, the following screenshot shows a 'docker-compose' file that creates a docker-compose service with a volume. As a result of the above command, a volume with the name 'myvolume' gets created.

Does Docker compose delete volumes?

Stops containers and removes containers, networks, volumes, and images created by up .


Video Answer


1 Answers

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
like image 162
BMitch Avatar answered Oct 02 '22 08:10

BMitch