We want to remove ads from the website, but we need your help.
Please donate some of your computer power to running our website.

19. February 2017

Docker remove untagged images and stopped container

During active development on and with Docker I have been extremely frustrated by lack of proper cleanup commands in Docker itself. Stopped containers and untagged images soon take your precious disk space and you are left wondering where it went as none of the directories has enough data inside to stand out. Docker is usually not the first place you would look (unless you have experience).

Remove stopped Docker containers

All stopped containers are usually not used. It will also complain when a used image is removed or anything else, so you can try it. This is not the part which takes most of your storage, but images used in containers cannot be deleted and since you were using image in past it should have a container connected to it anyway.

docker rm $(docker ps -a -q) 

Remove untagged Docker images

Untagged Docker images take most of the disk space. You can remove only unused images and it is mostly safe to assume that untagged images are just left overs from past development. If untagged image is used in another image, it will not want to delete it anyway.

docker rmi $(docker images | grep "^" | awk "{print $3}")

Newest from this category: