How to Remove Volume in Docker: Commands and Examples
To remove a Docker volume, use the
docker volume rm [VOLUME_NAME] command. To remove all unused volumes, use docker volume prune.Syntax
The basic command to remove a Docker volume is docker volume rm [VOLUME_NAME]. Replace [VOLUME_NAME] with the name of the volume you want to delete.
To remove all unused volumes (volumes not attached to any container), use docker volume prune. This command will ask for confirmation before deleting.
bash
docker volume rm [VOLUME_NAME] docker volume prune
Example
This example shows how to list Docker volumes, remove a specific volume, and then prune all unused volumes.
bash
docker volume ls
# Output shows volumes
docker volume rm my_volume
# Removes volume named 'my_volume'
docker volume prune
# Removes all unused volumes after confirmationOutput
DRIVER VOLUME NAME
local my_volume
local another_volume
my_volume
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
unused_volume_1
unused_volume_2
Common Pitfalls
One common mistake is trying to remove a volume that is still in use by a container. Docker will return an error in this case.
Always check if the volume is attached to any container before removing it. Use docker ps -a and docker inspect to verify.
bash
docker volume rm my_volume # Error: volume is in use docker rm -f container_using_volume # Remove container using the volume docker volume rm my_volume # Now volume removal succeeds
Output
Error response from daemon: remove my_volume: volume is in use - [container_using_volume]
container_using_volume
my_volume
Quick Reference
| Command | Description |
|---|---|
| docker volume ls | List all Docker volumes |
| docker volume rm [VOLUME_NAME] | Remove a specific volume |
| docker volume prune | Remove all unused volumes after confirmation |
| docker ps -a | List all containers to check volume usage |
| docker inspect [CONTAINER] | Inspect container details including volumes |
Key Takeaways
Use
docker volume rm [VOLUME_NAME] to remove a specific volume.Use
docker volume prune to clean up all unused volumes safely.Volumes in use by containers cannot be removed until containers are stopped or removed.
Always check volume usage before removal to avoid errors.
Pruning volumes helps free disk space by removing unused data.