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:
- how does one properly cleanup?
- as I was manually deleting images more started to arrive. huh?
- how much disk space should I really allocate to the host?
- will running daemons really restart after the next reboot?
and the meta question... what questions have I not asked that need to be?
Here's how I periodically purge my docker host:
Kill running containers:
Delete all containers (and their associated volumes):
Remove all images:
Update
Delete only the containers that are not running. Parse the "ps" output for the "Exited" string:
Not perfect... Don't give your container the name "Exited" :-)
Update
Docker 1.9 has a new volume command that can be used to purge old volumes
Update
Latest community edition of docker has a new "system prune" command
This purged unused networks, kill stopped containers, dangling images and any unused volumes.
Sometimes you wont have Status, it'll just be blank.
here is my version:
Update: There are built-in filters in the docker cli that let one properly display containers that meet certain criteria. These bash functions are taken from one of the core maintainers' dotfiles:
Original Answer
A helper script I've created for my own use:
source
To your questions:
no official way yet, just helper scripts and functions like the above.
you might have been deleting images that were built on top of others that became "untagged" when you tried to delete them.
depends on the types of images you plan to use. Know that running a 500 mb image multiple times doesn't use (500mb X number of containers) space. The containers reuse the same image and just add whatever they change when running on top. So think from an image storing perspective, not a container runtime one regarding storage.
By default, they are stopped when the host reboots. You need to run with
docker run --restart=True
to automatically start up again when the host reboots.I would also like to contribute to this with some commands that were added to version 1.13.0:
see changelog: 1.13.0 (2017-01-18)
I'm using docker-machine with VirtualBox and after deleting all containers and all images, the docker VirtualBox image is still consuming many gigabytes of disk space.
To also clean up the disk space, it helps to delete and re-create the docker machine. E.g.:
It can also be helpful to remove "dangling" images
docker rmi $(docker images -f "dangling=true" -q)