Overview
I often forget that volumes are not deleted even after removing containers and images in Docker, so I'm writing this note.
I usually use docker-compose.
docker-compose build
docker-compose up -d
Then, I clean up with:
docker rm **
docker rmi **
However, it seems there is an option to delete mounted volumes.
Solution
Check if volumes remain.
docker volume ls
docker volume rm **
Additional Notes
There is a way to clean up all containers, network images, and volumes described in docker-compose.yml at once using docker-compose.
docker-compose down --rmi all -v
How to Delete Docker Volumes
Removing images and containers leaves volumes behind. Delete the leftover volumes with these steps.
First, list the volumes that remain.
docker volume ls
Next, delete a specific volume by name.
docker volume rm <volume-name>
To remove every volume that no containers reference, run:
docker volume prune
With Docker Compose, add -v to down to delete the volumes it defined.
docker compose down -v
To clean up images as well, add --rmi all.
docker compose down --rmi all -v
Related posts
- Docker Compose env vars not recognized
- Docker in cron: the input device is not a TTY
- Elasticsearch and Kibana with Docker