Chris Stryczynski
Chris Stryczynski

Reputation: 34109

Remove a single named volume with docker-compose?

Is this possible from docker-compose - or do I have identify the volumes location and delete them?

I can only find functionality to delete ALL the volumes associated with the docker-compose.yaml config file.

Upvotes: 8

Views: 4912

Answers (1)

Matt
Matt

Reputation: 74919

Compose can only remove all volumes defined in a yml file, or none

$ docker-compose down -v 

If you don't want to investigate which volumes are used for the current compose file and remove them with docker volume rm X, then create a cutdown compose file that only lists the volumes you want to remove

docker-compose.yml

version: "2.1"
volumes:
  one:
  two:
  three:

docker-compose-cleanup.yml

version: "2.1"
volumes:
  two:

Then you can act on different sets depending on the compose file

$ docker-compose up
Creating volume "composevolumes_three" with default driver
Creating volume "composevolumes_two" with default driver
Creating volume "composevolumes_one" with default driver
Attaching to 
$ docker-compose -f docker-compose-cleanup.yml down -v
Removing volume composevolumes_two

Upvotes: 13

Related Questions