Clean up your Docker…

Two commands to clean up images and containers.

Docker is great, but while testing builds and improving your Dockerfile, it’s very easy to pollute your Docker environment with orphaned images and containers.

These take up space on your computer, and there is no quick and easy command to clean it all up. I’ve found the following commands are great are keeping a tidy Docker environment.

The following command will remove all non-running Docker containers:

docker rm `docker ps -aq --no-trunc --filter "status=exited"`

The following command will remove all orphaned Docker images:

docker rmi `docker images --filter 'dangling=true' -q --no-trunc`

Kudos to this stackoverflow post for the commands.