If I have a docker-compose file like:
version: "3" services: postgres: image: postgres:9.4 volumes: - db-data:/var/lib/db volumes: db-data:
... then doing docker-compose up
creates a named volume for db-data
. Is there a way to remove this volume via docker-compose
? If it were an anonymous volume, then docker-compose rm -v postgres
would do the trick. But as it stands, I don't know how to remove the db-data
volume without reverting to docker
commands. It feels like this should be possible from within the docker-compose
CLI. Am I missing something?
Remove one or more specific volumes - Docker 1.9 and laterUse the docker volume ls command to locate the volume name or names you wish to delete. Then you can remove one or more volumes with the docker volume rm command: List: docker volume ls.
Stops containers and removes containers, networks, volumes, and images created by up .
To remove one or more Docker volumes, run the docker volume ls command to find the ID of the volumes you want to remove. If you get an error similar to the one shown below, it means that an existing container uses the volume. To remove the volume, you will have to remove the container first.
This command removes the container and any volumes associated with it. Note that if a volume was specified with a name, it will not be removed.
docker-compose down -v
removes all volumes attached. See the docs
There's no way to target the removal of a specific named volume with the docker-compose
cli. Instead this can be achieved using the docker
cli. See the docs.
Use docker volume ls
to find the name of specific volume.
Remove the volume using docker volume rm VOLUME_NAME
. You will need to have stopped and removed containers using the volume.
An example approach:
# Stop and remove container's using the target volume docker-compose stop NAME_OF_CONTAINER # We need the force flag, "-f", as the container is still bound to the volume docker-compose rm -f NAME_OF_CONTAINER # Next find your volume name in the following list docker volume ls # Finally remove the volume docker volume rm VOLUME_NAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With