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:
6cef5384f93c7e6bdbe0a8193fb1f134220b44cb2b497f758dd7a840ed10fc21
....
d255bdaaee4cb807d4897ce8dd71e0638aaa13dc4619014998579c2d29913d15

Deleted Volumes:
01a73b76d52a9b26e07bc4f828861a35ad77ef32eaddb65702e8489171e90214
....

Deleted Networks:
journals_default
....

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