As I create/debug a docker image/container docker seems to be leaving all sorts of artifacts on my system. (at one point there was a 48 image limit) But the last time I looked there were 20-25 images; docker images
.
So the overarching questions are:
and the meta question... what questions have I not asked that need to be?
How to cleanup docker containers? docker container rm has two useful options: -v or --volumes which will remove volumes associated with the container being removed. -f or --force which will force the removal of the container with SIGKILL.
Volumes are removed using the docker volume rm command. You can also use the docker volume prune command.
Here's how I periodically purge my docker host:
Kill running containers:
docker kill $(docker ps -qa)
Delete all containers (and their associated volumes):
docker rm -v $(docker ps -qa)
Remove all images:
docker rmi $(docker images -q)
Delete only the containers that are not running. Parse the "ps" output for the "Exited" string:
docker ps -a | awk '/Exited/ {print $1}' | xargs docker rm -v
Not perfect... Don't give your container the name "Exited" :-)
Docker 1.9 has a new volume command that can be used to purge old volumes
docker volume rm $(docker volume ls -qf dangling=true)
Latest community edition of docker has a new "system prune" command
docker system prune --volumes
This purged unused networks, kill stopped containers, dangling images and any unused volumes.
It can also be helpful to remove "dangling" images
docker rmi $(docker images -f "dangling=true" -q)
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