Docker host cleanup

Free up space on your Docker host

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.

1
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.

1
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.

1
docker system prune -a