Infrastructure 2019-04-28 ⏱ 1 min read

Note on Volumes Not Being Deleted Even After Removing Docker Images and Containers

Learn why Docker volumes persist after removing containers and images, how to inspect and remove orphaned volumes with docker volume ls/rm, and the shortcut docker-compose down --rmi all -v.

Read in: ja
Note on Volumes Not Being Deleted Even After Removing Docker Images and Containers

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

References

Tags: Docker Docker Compose
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles