Usefull commands to clean up docker's unused objects.
Using docker also fills up the filesystem over time. To free up disk space you could run one or more of the following docker commands.
Prune...
What are the images on the disk and how old are they?$ sudo docker info Containers: 79 Running: 2 Paused: 0 Stopped: 77 Images: 606 Server Version: 18.06.1-ce Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e runc version: 69663f0bd4b60df09991c08812a60108003fa340 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 5.14 Operating System: Linux OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 8GiB Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
Purge (prune) all dangling images.$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE Appl1 latest b5bb13cb985a 4 weeks ago 778MB7772b26a8a8a 4 weeks ago 778MB 4d4802dc65e8 10 months ago 775MB dfdede74091a 10 months ago 775MB 73f75a11728f 10 months ago 775MB 211cda896521 10 months ago 775MB .. myApp latest af9783e0efe6 16 months ago 813MB fcad22431d66 2 years ago 685MB 0cdd694b9cb9 2 years ago 685MB b46b547c4ca0 2 years ago 767MB .. 3332127cf358 2 years ago 760MB ubuntu latest 47b19964fb50 2 years ago 88.1MB python 3-onbuild 3f246dd60a17 2 years ago 685MB
List all the images.$ sudo docker image prune WARNING! This will remove all dangling images. Are you sure you want to continue? [y/N] y Deleted Images: deleted: sha256:dfdede74091a38eb2b5150decf9e78405a7feedb6dfc5143f2c78c399c63b169 deleted: sha256:f3a49c636061d5291f28d80b1caa6737eebac1eeefca19b9700e7f8ab2c5a355 .. deleted: sha256:c6ecc919dcc09308674fc2456f2b9bde8bacb91e916782658e1c9e31279df2a4 deleted: sha256:70c2c20203743197a0e19e5bdb75dc7769e4d75642a496ed115fa90021e7fcd9 deleted: sha256:925adb3b9a1937025f18f99e2744e9b2c96a4a06fc3b3d49bbbbf0e07cb9f0bf deleted: sha256:60fb7bea922786b469610a1bb4f71b96de5ee5f414f513905e073d96a728b34f Total reclaimed space: 9.167MB
Prune the containers that are stopped.$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE myappl latest b5bb13cb985a 4 weeks ago 778MB7772b26a8a8a 4 weeks ago 778MB 4d4802dc65e8 10 months ago 775MB 73f75a11728f 10 months ago 775MB .. 692649106fd9 2 years ago 760MB 3332127cf358 2 years ago 760MB ubuntu latest 47b19964fb50 2 years ago 88.1MB python 3-onbuild 3f246dd60a17 2 years ago 685MB
Show the running processes, if they are still running... ;-)$ sudo docker container prune WARNING! This will remove all stopped containers. Are you sure you want to continue? [y/N] y Deleted Containers: 83aa171dd1a9e7ed26201b44b26deca823d8297307073a4f991162a45cfacb29 deac602308917e24107f6df717a32e53101f0725d2b80b70b5b5f20553c20c04 758947a9ec4dc60f0e82183c20fb71a73f438a6836b21f77545fcf54a7040517 f1c170d54570c0b30434c67e46b347006d7ffd6424e9791b5baeeae81366e15d .. 93316ca2f25fe000031338b3f25b91cdd1cc61dd0520cbe0bf9a5991c7d935de 5c6f2dd181e9a6a0c308d2f99f3b61f4e259a466d8e9d0281944721d12e638ae 5fc6a246a3059036bcbd72f3ebf13ef943e72cdf5cf079f327ae44ced87a07a0 03f90a57994b804ab0a2d0d6e16123415975d6abf027cd7e6ff1833382fd47e2 Total reclaimed space: 409.4MB
What docker images do we have on the system?$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0a9d0a93ba7a myAppl "python -m myAppl…" 20 hours ago Up 20 hours 5000/tcp, 0.0.0.0:8000->8000/tcp myAppl 9c99235464af Appl1 "/sbin/entrypoint.sh" 4 weeks ago Up 4 weeks 0.0.0.0:80->80/tcp, 443/tcp wizardly_mcflurry
Clean all the dangling images.$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE Appl1 latest b5bb13cb985a 4 weeks ago 778MB73f75a11728f 10 months ago 775MB 211cda896521 10 months ago 775MB .. c6437f5978c4 2 years ago 760MB 3332127cf358 2 years ago 760MB ubuntu latest 47b19964fb50 2 years ago 88.1MB python 3-onbuild 3f246dd60a17 2 years ago 685MB
$ sudo docker image prune WARNING! This will remove all dangling images. Are you sure you want to continue? [y/N] y Deleted Images: deleted: sha256:72dee1e996b35c79be1f6275eed5e97d4fa6bc8d359fe34441d2d0096abc4525 deleted: sha256:69b78a6b0e20f92c5c4b2ba58365fa8369467e00e7f2e0644eb6d23881b81acb deleted: sha256:e9f6c36fc6a734a33bf867bfde628c26087a1a17bd56ca86d12334a351fdf8e3 .. deleted: sha256:c7f112ce5a2392885b9f33cf1108dcaa181a370ace3e70aa276e3eb6c1bfbc32 deleted: sha256:64ab40d8c6f8c3a5646f558753788e2db77120ee24161341e1db543f3c076616 deleted: sha256:84d8752bb29f56bea6582bf413ca21160482f94fe996c289661ae7f74b1444ac deleted: sha256:558e8039798d7723a6fdbedef4ce9f9aba6cf74d6d8021002920291097882b2e Total reclaimed space: 646.4MB
And test once more.
$ sudo docker image prune WARNING! This will remove all dangling images. Are you sure you want to continue? [y/N] n Total reclaimed space: 0B
Published: 16.11.2020