{"id":2000,"date":"2023-12-20T11:51:07","date_gmt":"2023-12-20T02:51:07","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=2000"},"modified":"2023-12-22T14:53:27","modified_gmt":"2023-12-22T05:53:27","slug":"ubuntu-22_04-delete-old-docker-images-built-more-than-6-months-ago","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2023\/12\/20\/ubuntu-22_04-delete-old-docker-images-built-more-than-6-months-ago\/","title":{"rendered":"Ubuntu 22.04: \u53e4\u3044 Docker images \u3092\u524a\u9664\u3059\u308b"},"content":{"rendered":"<p>&nbsp;<br \/>\n\u3082\u3046\u305a\u3063\u3068\u524d\u306b\u30d3\u30eb\u30c9\u3057\u3066\u4ee5\u964d\u3001\u3082\u306f\u3084\u4f7f\u3063\u3066\u306a\u3044 docker images \u306e\u6b8b\u9ab8\u304c\u30ed\u30fc\u30ab\u30eb\u306b\u3044\u3063\u3071\u3044\u6b8b\u3063\u3066\u305f\u306e\u3067\u30e1\u30e2\u3002<\/p>\n<p>Docker \u304c\u4eca\u3069\u308c\u3060\u3051\u30b9\u30c8\u30ec\u30fc\u30b8\u3092\u4f7f\u3063\u3066\u308b\u304b\u3092\u78ba\u8a8d\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker system df\r\n<\/pre>\n<p>6\u30f6\u6708\u4ee5\u4e0a\u524d\u306b\u30d3\u30eb\u30c9\u3057\u305f\u30a4\u30e1\u30fc\u30b8\u3092\u524a\u9664\u3059\u308b\u306e\u3068\u3001\u3042\u3068\u306f\u30d3\u30eb\u30c9\u30ad\u30e3\u30c3\u30b7\u30e5\u3082\u5168\u90e8\u524a\u9664\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n\r\nsix_mo_ago=$(date -d &quot;6 month ago&quot; +%s)\r\n\r\ndocker images --format &quot;{{.Repository}}:{{.Tag}} {{.CreatedAt}}&quot; | while read image date; do\r\n    datepart=$(echo $date | awk '{print $1}')\r\n    image_date=$(date -d &quot;$datepart&quot; +%s)\r\n    if &#x5B; $image_date -lt $six_mo_ago ]; then\r\n        echo &quot;Removing $image...&quot;\r\n        docker rmi -f $image\r\n    fi\r\ndone\r\n\r\ndocker builder prune -f\r\n<\/pre>\n<p>6\u30f6\u6708\u4ee5\u4e0a\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3057\u3066\u306a\u3044\u30a4\u30e1\u30fc\u30b8\u3082\u3053\u308c\u3067\u6d88\u3048\u3061\u3083\u3046\u306e\u3067\u3001\u305d\u3053\u306f\u6ce8\u610f\u3002<\/p>\n<p>\u7279\u5b9a\u306e\u6587\u5b57\u5217\u3092\u542b\u3080\u30a4\u30e1\u30fc\u30b8\u3060\u3051\u306b\u7d5e\u308a\u305f\u3044\u306a\u3089\u3001 \u4e0b\u8a18\u307f\u305f\u3044\u306b while \u30eb\u30fc\u30d7\u306e\u524d\u306b grep \u3059\u308c\u3070\u826f\u3044\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ndocker images --format &quot;{{.Repository}}:{{.Tag}} {{.CreatedAt}}&quot; | grep -E 'foo|bar|baz' | while read image date; do\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u3082\u3046\u305a\u3063\u3068\u524d\u306b\u30d3\u30eb\u30c9\u3057\u3066\u4ee5\u964d\u3001\u3082\u306f\u3084\u4f7f\u3063\u3066\u306a\u3044 docker images \u306e\u6b8b\u9ab8\u304c\u30ed\u30fc\u30ab\u30eb\u306b\u3044\u3063\u3071\u3044\u6b8b\u3063\u3066\u305f\u306e\u3067\u30e1\u30e2\u3002 Docker \u304c\u4eca\u3069\u308c\u3060\u3051\u30b9\u30c8\u30ec\u30fc\u30b8\u3092\u4f7f\u3063\u3066\u308b\u304b\u3092\u78ba\u8a8d\u3002 docker system [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,8],"tags":[],"class_list":["post-2000","post","type-post","status-publish","format-standard","hentry","category-docker","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=2000"}],"version-history":[{"count":4,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2000\/revisions"}],"predecessor-version":[{"id":2004,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2000\/revisions\/2004"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=2000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=2000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=2000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}