Docker host cleanup

Docker host cleanup

Free up space on your Docker host

·1 min read
Contents

WARNING: commands below delete stopped containers and remove all their data. Make sure you don't have any containers or valuable data that you need to backup.

Remove __*exited*__ containers

When a docker container exits, it leaves the stopped container on the system. Below command will remove that stopped container.

bash
docker rm -v $(docker ps -a -q -f status=exited)

Remove __*dangling*__ images

Docker keeps all of the images that you have used in the disk (local cache), even if those are not actively running. Below command will remove all those unwanted images.

bash
docker rmi $(docker images -f "dangling=true" -q)

All-in-one command

Execute below command if you want to delete and remove any stopped containers and unused images.

bash
docker system prune -a

Keep reading