Docker container cleanup made easy with Docker 17.05

Earlier docker container and images would keep on occupying spaces until unless manually cleaned up. The clean command included piped commands.

For example to clean all exited contained

$ docker ps -a -q -f status=exited | xargs docker rm -v 

And to delete volumes or images different commands had to be used. But with Docker 17.05 now out. This is a simple command

$ docker system prune

If you don’t want any confirmation, then add the -f flag at the end

$ docker system prune -f
WARNING! This will remove:
	- all stopped containers
	- all volumes not used by at least one container
	- all networks not used by at least one container
	- all dangling images
Are you sure you want to continue? [y/N] y
Deleted Containers:

Deleted Volumes:

Deleted Networks:

Deleted Images:
deleted: sha256:0b5a2cad4b1e7763bf920cc631abbc0cf3e9ceb49fe4363c4bed5d4af83b9321

Total reclaimed space: 5.184GB

As you can see I reclaimed 5GB+ space on my VM, which earlier required multpile commands. The system command also has a df subcommand which shows disk usage

vagrant@vagrant:~$ docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              36                  0                   8.301GB             8.301GB (100%)
Containers          0                   0                   0B                  0B
Local Volumes       0                   0                   0B                  0B