We come across the challenge to manage the docker engine and its disk space consumption issues in a long run.
To effectively manage its resources we have some of the best options, let us take a look at them in this tutorial.
How to identify the details of disk space usage in docker ?
[root@node01 ~]# docker system df -v
[root@node01 ~]# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 7 3 1.442 GB 744.2 MB (51%) Containers 3 1 2.111 MB 0 B (0%) Local Volumes 7 1 251.9 MB 167.8 MB (66%)
This command prints the complete verbose details of Images space usage, Containers space usage and Local Volumes space usage
How to Clean up space on Docker ?
[root@node02 vamshi]# docker system prune [ -a | -f ]
The option -a
: Removes all the unused images and the stale containers / images
and -f
Forcefully removes the unused images and the stale containers without prompting for confirmation.How
How to Remove docker images?
The docker images can be removed using the docker image rm <container-id | container-name>
command.
The command docker rmi
is most commonly used also the [/code]docker image rm[/code] which is more easier to read and self explanatory.
[root@node02 vamshi]# docker rmi
The docker images which are dangling and those without any tags can be filtered out using the below syntax and can be removed to save some file system space
We can list out the docker images that are dangling using the filter option as shown below:
# docker images -f "dangling=true"
The list of images received from the above command we pass only the image id’s to the docker image rm command as shown below:
[root@node02 vamshi]# docker image rm $(docker images -qf "dangling=true")
How to list multiple docker images with matching pattern ?
[vamshi@node02 ~]$ docker image ls mysql* REPOSITORY TAG IMAGE ID CREATED SIZE rrskris/mysql v1 1ab47cba1d63 4 months ago 456 MB rrskris/mysql v2 3bd34czc2b90 4 months ago 456 MB docker.io/mysql latest d435eee2caa5 5 months ago 456 MB
How to remove multiple docker containers with matching pattern
The docker provides good amount of flexibility with the commandline and can be combined with regular expression and awk formatting commands to yield relevant results.
[vamshi@node02 ~]$ docker image rm $(docker image ls | grep -w "^old-image" | awk {'print $3'} )