{"id":163,"date":"2019-11-10T16:25:00","date_gmt":"2019-11-10T21:25:00","guid":{"rendered":"http:\/\/127.0.0.1:8080\/?p=163"},"modified":"2024-01-13T14:04:00","modified_gmt":"2024-01-13T19:04:00","slug":"how-to-clean-old-oci-docker-images","status":"publish","type":"post","link":"http:\/\/10.42.0.68:8080\/blog\/how-to-clean-old-oci-docker-images","title":{"rendered":"How to clean old OCI\/Docker images"},"content":{"rendered":"\n

To save disk space, use these example scripts for podman and Docker to remove outdated OCI\/Docker images from your servers.<\/p>\n\n\n\n\n\n\n\n

Why doing it?<\/h2>\n\n\n\n

I utilize Drone Agent for building Docker images, which results in an accumulation of numerous legacy images.<\/p>\n\n\n\n

1 image = space disk used for nothing<\/p>\n\n\n\n

For example, I build big images:<\/p>\n\n\n\n

quay.io\/sycured\/latex-builder   2.69 GB\nquay.io\/sycured\/buildah-vfs     474 MB<\/code><\/pre>\n\n\n\n

When I rebuild latex-builder, it’s 2.69 GB, so when you have 5 or 6 old images, you lose more than 10 GB of disk space, and my VM for Drone Agent is just 50 GB of disk space.<\/p>\n\n\n\n

Cleaning it is required but also in prod because you lose a lot of space disk for nothing.<\/p>\n\n\n\n

KISS is the best: cron<\/h2>\n\n\n\n

Keep It Simple Stupid, cron is the best solution to do it.<\/p>\n\n\n\n

Insert the appropriate snippet into\u00a0\/etc\/cron.daily\/clean_old_images<\/code>\u00a0and apply executable permissions using\u00a0chmod +x \/etc\/cron.daily\/clean_old_images<\/code>. This approach is ideal if operating as the root user. Otherwise, you can add it to the user crontab.<\/p>\n\n\n\n

For Podman<\/h3>\n\n\n\n
#!\/bin\/bash\npodman images | awk '\/none\/ {system(\"podman rmi -f \" $3)}'<\/code><\/pre>\n\n\n\n

For Docker<\/h3>\n\n\n\n
#!\/bin\/bash\ndocker images | awk '\/none\/ {system(\"docker rmi -f \" $3)}'<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

To save disk space, use these example scripts for podman and Docker to remove outdated OCI\/Docker images from your servers.<\/p>\n","protected":false},"author":1,"featured_media":80,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"saved_in_kubio":false,"footnotes":""},"categories":[14],"tags":[15],"_links":{"self":[{"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/posts\/163"}],"collection":[{"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":1,"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":164,"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/posts\/163\/revisions\/164"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/media\/80"}],"wp:attachment":[{"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10.42.0.68:8080\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}