After reading through many tutorials, and testing different features of Docker you may have some containers and images left in unexpected states.
We've compiled a list of useful commands so you can look into your docker system and clean things up if necessary.
$ docker ps # lists running containers $ docker ps -a # list all containers
$ docker stop XXX # first few chars of container id $ docker stop $(docker ps -a)
$ docker rm XXX # first few characters of container id $ docker rm $(docker ps -aq) # remove all containers $ docker rm -v $(docker ps -aq) # remove all containers and their volumes
-q flag displays only the numeric id
$ docker images # default hides intermediates $ docker image ls -a # lists all images, including intermediates
$ docker image rm XXX # first few chars of image id $ docker rmi XXX # shortform $ docker rmi $(docker images -q) # remove all images
$ docker volume ls $ docker volume ls -f dangling=true # show dangling
** Remove Volume **
$ docker volume rm myvolume $ docker volume rm myvolume -f # force remove
$ docker volume prune WARNING! This will remove all volumes not used by at least one container. Are you sure you want to continue? [y/N] y Deleted Volumes: 07c7bdf3e34ab76d921894c2b834f073721fccfbbcba792aa7648e3a7a664c2e my-named-vol Total reclaimed space: 36 B
This command helps clean up the whole system:
$ docker system prune WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all build cache Are you sure you want to continue? [y/N] y
And for even deeper cleaning:
docker system prune -a --volumes WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all volumes not used by at least one container - all images without at least one container associated to them - all build cache Are you sure you want to continue? [y/N] y
I wanted give you an organized list of how to systematically think about your docker system which will make it easier understand how elements work together. If there are any other suggestions you have to keep your deck spotless, please share in the comments!