Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 835
Chris Stryczynski Avatar asked Oct 18 '17 14:10

Chris Stryczynski


People also ask

Does docker-compose down Remove named volumes?

Networks and volumes defined as external are never removed. Anonymous volumes are not removed by default.

Can I delete docker volume?

You cannot remove a volume that is in use by a container. For example uses of this command, refer to the examples section below.

How do I stop a specific service in docker-compose?

There are two steps to stop a docker application containers: First, stop the running containers using docker-compose stop. Second, remove the stopped containers using docker-compose rm -f.


1 Answers

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
like image 199
Matt Avatar answered Nov 11 '22 15:11

Matt