1.关于删除私有仓库的镜像,官网说明如下:
官网上注明可以通过name和digest删除image。name我们是知道的。我们只要获取digest就可以了!
查看所有镜像:
查看指定镜像:
2.registry启动依赖config.yml配置文件:在默认文件的storage区域中添加delete_enable_ture配置项(默认不添加)。也可以在启动时候指定-e添加。允许删除镜像:
下图是仓库磁盘使用情况:
3.获取某个镜像(如api-service服务)的digest(需要进入私有仓库容器,参考上一步)(没有清理的仓库,历史镜像有很多):
4.删除镜像(接上一步)(用awk拼接出删除镜像的URL,然后批量执行):
/var/lib/registry/docker/registry/v2 # ls -l repositories/api-service/_manifests/tags/0.0.1-SNAPSHOT/index/sha256/|grep -v "total 0"|awk '{print"curl -I -X DELETE https://sxxh-docker001.lo:5000/v2/api-service/manifests/sha256:"$9}'
curl -I -X DELETE https://sxxh-docker001.lo:5000/v2/api-service/manifests/sha256:001b7aac44f7879861eaa310375d339ae28801e8c3784ab229a04880789b3030
curl -I -X DELETE https://sxxh-docker001.lo:5000/v2/api-service/manifests/sha256:008e0311afc9842aa5968c309fade709f84f19e1e1b4f740679fbc2c0f07a422
curl -I -X DELETE https://sxxh-docker001.lo:5000/v2/api-service/manifests/sha256:04b41e1d6af713ebc13f219c39ba8e9c6c10896e7f80ce33301ee58152019aa7
curl -I -X DELETE https://sxxh-docker001.lo:5000/v2/api-service/manifests/sha256:04b6e9563f6b2f0acd337c2c2baf1a068eaadaf0dcfae77a1779ee8ed47da3d4
curl -I -X DELETE https://sxxh-docker001.lo:5000/v2/api-service/manifests/sha256:04efcac51201b2d5d2fda9fbac5e4865662495bbe7ac10d3056d0102a4cfa78a
curl -I -X DELETE https://sxxh-docker001.lo:5000/v2/api-service/manifests/sha256:06c019b03712670db4943a20a4b765de0d99002193c4160550ceca64d6333c72
curl -I -X DELETE https://scxxh-docker001.lo:5000/v2/api-service/manifests/sha256:085bca22b063f7ac0615f6c6154f960da35d4ceb5236f74e741271f3288d73a7
如上图,删除成功!
5.上面步骤只是删除了image的元数据信息(索引)。现在进入registry中进行垃圾回收命令如下:
registry garbage-collect /etc/docker/registry/config.yml
删除结果如下(部分):
6.其他:获取digest也可以使用其他方法(但是如果历史镜像很多,显示貌似有问题,没仔细研究)。如下:
[root@sxxh-docker002 ~]# curl https://sxxh-docker001.lo:5000/v2/web-service/manifests/0.0.1-SNAPSHOT { "schemaVersion": 1, "name": "web-service", "tag": "0.0.1-SNAPSHOT", "architecture": "amd64", "fsLayers": [ { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:95edc035592e218bf92a7d08a04f0c7d587f5a14385a0d5f6f62e806fa7693a2" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:054d5672a4a8d76a4f37dbd922f73e5a93a9799af8868795dd427af43d2e9827" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:0a2b7222259b98cf41d67ce95433b5410e85ff8492c5c47254b60a0ca56a9271" }, { "blobSum": "sha256:81cf5426393a4ac116dac26d8e0f95ea3ba85afcc09bc6eafdbd2efc598aa180" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:813b623203785421e2ad013759851cd6069d7f88dfc0211a091aad6b51ea465b" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:c7a02d193df75b11859dfcf15697ec0821e6a0f39d9dec6c9c4477955554d0db" }, { "blobSum": "sha256:624ba6156166d75b89cefff243adfa3d60384629102ab210b7a049c0464a2aa7" }, { "blobSum": "sha256:3318dd58ae6084d70d299efb50bcdf63e861f2dc3d787e03a751581e606442d9" }, { "blobSum": "sha256:8d9ed335b7dbe095ecfbbfe0857d07971283db0119f7a4aa490f9cbe06187335" }, { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:e12c678537aee9a1a1be8197da115e7c4d01f2652344f492a50ca8def9993d1e" } ], "history": [ { "v1Compatibility": "{"architecture":"amd64","author":"统一Maven版本依赖","config":{"Hostname":"33842653d6db","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64","JAVA_VERSION=8u111","JAVA_DEBIAN_VERSION=8u111-b14-2~bpo8+1","CA_CERTIFICATES_JAVA_VERSION=20140324","TZ=Asia/Shanghai"],"Cmd":null,"ArgsEscaped":true,"Image":"sha256:df682f932e08fd0fbd0fabbdbd033183e3115f57c7f00d5d0678448d2c364ad8","Volumes":{"/tmp":{}},"WorkingDir":"","Entrypoint":["java","-jar","/web-service-0.0.1-SNAPSHOT.jar"],"OnBuild":[],"Labels":{}},"container":"d38226cf23843b0df2bbaefa8cd89022d7ffea8fb18be63174eddc23a6e1f870","container_config":{"Hostname":"33842653d6db","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64","JAVA_VERSION=8u111","JAVA_DEBIAN_VERSION=8u111-b14-2~bpo8+1","CA_CERTIFICATES_JAVA_VERSION=20140324","TZ=Asia/Shanghai"],"Cmd":["/bin/sh","-c","#(nop) ","VOLUME [/tmp]"],"ArgsEscaped":true,"Image":"sha256:df682f932e08fd0fbd0fabbdbd033183e3115f57c7f00d5d0678448d2c364ad8","Volumes":{"/tmp":{}},"WorkingDir":"","Entrypoint":["java","-jar","/web-service-0.0.1-SNAPSHOT.jar"],"OnBuild":[],"Labels":{}},"created":"2018-04-16T08:12:12.377573866Z","docker_version":"17.03.1-ce","id":"051756db9ef951ec6e9452b85d2981f74c1a849cb58c1a7b10324399e92fab05","os":"linux","parent":"07e9eac23fce9b48c1703a5afcf1331a2d9f342cf89fd4fd36fd2b5ebdbc769f","throwaway":true}" }, { "v1Compatibility": "{"id":"07e9eac23fce9b48c1703a5afcf1331a2d9f342cf89fd4fd36fd2b5ebdbc769f","parent":"a03985d32e0e7e0d2b7fd528f29b399efb948fec5da591f7e20d98aa0f8d2b56","created":"2018-04-16T08:12:10.033500448Z","container_config":{"Cmd":["/bin/sh -c #(nop) ENTRYPOINT [\"java\" \"-jar\" \"/web-service-0.0.1-SNAPSHOT.jar\"]"]},"author":"统一Maven版本依赖","throwaway":true}" }, { "v1Compatibility": "{"id":"a03985d32e0e7e0d2b7fd528f29b399efb948fec5da591f7e20d98aa0f8d2b56","parent":"ca071fc3fa4df214579dd746c8688f217dba0281cfb48fa856e8de3c98294299","created":"2018-04-16T08:12:08.181245759Z","container_config":{"Cmd":["/bin/sh -c #(nop) ADD file:72c2b113c156719c5846f0888e2d65fd2c69abe32b85ee3e9930a6e987a54873 in // "]},"author":"统一Maven版本依赖"}" }, { "v1Compatibility": "{"id":"ca071fc3fa4df214579dd746c8688f217dba0281cfb48fa856e8de3c98294299","parent":"cf2bea30fd3a5447838f21d8d85e399e79ce6f15395e839771590b308d2aaada","created":"2018-03-30T07:19:59.569600284Z","container_config":{"Cmd":["/bin/sh -c #(nop) MAINTAINER 统一Maven版本依赖"]},"author":"统一Maven版本依赖","throwaway":true}" }, { "v1Compatibility": "{"id":"cf2bea30fd3a5447838f21d8d85e399e79ce6f15395e839771590b308d2aaada","parent":"3c057fbea6207ba9a2b823dd17f145f2f2fcf6db1472062486e6701b1bb4cc6c","created":"2017-10-17T07:04:47.230082637Z","container_config":{"Cmd":["/bin/sh -c ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \u0026\u0026 echo $TZ \u003e /etc/timezone"]}}" }, { "v1Compatibility": "{"id":"3c057fbea6207ba9a2b823dd17f145f2f2fcf6db1472062486e6701b1bb4cc6c","parent":"0331530cc61a4109413744b40320a54b814d64b00e94e1d30d8d7dc88a4efecc","created":"2017-10-17T07:04:43.346160813Z","container_config":{"Cmd":["/bin/sh -c #(nop) ENV TZ=Asia/Shanghai"]},"throwaway":true}" }, { "v1Compatibility": "{"id":"0331530cc61a4109413744b40320a54b814d64b00e94e1d30d8d7dc88a4efecc","parent":"ae1adbef900f22a6c8d52f8a5d0bee556572227d114adbd0e6c7028843c76a11","created":"2017-01-17T00:52:54.890877145Z","container_config":{"Cmd":["/bin/sh -c /var/lib/dpkg/info/ca-certificates-java.postinst configure"]}}" }, { "v1Compatibility": "{"id":"ae1adbef900f22a6c8d52f8a5d0bee556572227d114adbd0e6c7028843c76a11","parent":"4a4ced94bfab216abf2abe264900120cfb2db2e149b5a670315b62cc823ccd91","created":"2017-01-17T00:52:53.062156474Z","container_config":{"Cmd":["/bin/sh -c set -x \t\u0026\u0026 apt-get update \t\u0026\u0026 apt-get install -y \t\topenjdk-8-jdk=\"$JAVA_DEBIAN_VERSION\" \t\tca-certificates-java=\"$CA_CERTIFICATES_JAVA_VERSION\" \t\u0026\u0026 rm -rf /var/lib/apt/lists/* \t\u0026\u0026 [ \"$JAVA_HOME\" = \"$(docker-java-home)\" ]"]}}" }, { "v1Compatibility": "{"id":"4a4ced94bfab216abf2abe264900120cfb2db2e149b5a670315b62cc823ccd91","parent":"1ba36725ad52df8df858da07fc04e4b98cc03762f67911b1c4aea55cd2257604","created":"2017-01-17T00:51:50.743926212Z","container_config":{"Cmd":["/bin/sh -c #(nop) ENV CA_CERTIFICATES_JAVA_VERSION=20140324"]},"throwaway":true}" }, { "v1Compatibility": "{"id":"1ba36725ad52df8df858da07fc04e4b98cc03762f67911b1c4aea55cd2257604","parent":"a46acdc5fd926ac28ff88efe97f57bc3e0d62174bff1d0ce43c3c3fd7acfdcf0","created":"2017-01-17T00:51:50.391717354Z","container_config":{"Cmd":["/bin/sh -c #(nop) ENV JAVA_DEBIAN_VERSION=8u111-b14-2~bpo8+1"]},"throwaway":true}" }, { "v1Compatibility": "{"id":"a46acdc5fd926ac28ff88efe97f57bc3e0d62174bff1d0ce43c3c3fd7acfdcf0","parent":"6842fc455f496bc87a45f64380c2f0366dac050b6d90c4b40855440c5f905c47","created":"2017-01-17T00:51:50.099715912Z","container_config":{"Cmd":["/bin/sh -c #(nop) ENV JAVA_VERSION=8u111"]},"throwaway":true}" }, { "v1Compatibility": "{"id":"6842fc455f496bc87a45f64380c2f0366dac050b6d90c4b40855440c5f905c47","parent":"8ebd976b93669bca3dfd72cfbad438567b7415cac0ecb519dc5d040411345496","created":"2017-01-17T00:51:49.822140353Z","container_config":{"Cmd":["/bin/sh -c #(nop) ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64"]},"throwaway":true}" }, { "v1Compatibility": "{"id":"8ebd976b93669bca3dfd72cfbad438567b7415cac0ecb519dc5d040411345496","parent":"cff77c62e3e489f43b36f21a37a8e5b3042b250e58aacf2da34229057e96ce5b","created":"2017-01-17T00:51:49.52423661Z","container_config":{"Cmd":["/bin/sh -c { \t\techo '#!/bin/sh'; \t\techo 'set -e'; \t\techo; \t\techo 'dirname \"$(dirname \"$(readlink -f \"$(which javac || which java)\")\")\"'; \t} \u003e /usr/local/bin/docker-java-home \t\u0026\u0026 chmod +x /usr/local/bin/docker-java-home"]}}" }, { "v1Compatibility": "{"id":"cff77c62e3e489f43b36f21a37a8e5b3042b250e58aacf2da34229057e96ce5b","parent":"cae57b7d75ad8496a8822d6b5a6ad12f8aa41afedf8ac392ec7076e9bb4fbc2f","created":"2017-01-17T00:51:48.563377618Z","container_config":{"Cmd":["/bin/sh -c #(nop) ENV LANG=C.UTF-8"]},"throwaway":true}" }, { "v1Compatibility": "{"id":"cae57b7d75ad8496a8822d6b5a6ad12f8aa41afedf8ac392ec7076e9bb4fbc2f","parent":"460e9e88f2e3e275a94af3830c839674b2ca2af8140c1d46b1d60f7eb1ee00b5","created":"2017-01-17T00:51:48.199853506Z","container_config":{"Cmd":["/bin/sh -c echo 'deb http://deb.debian.org/debian jessie-backports main' \u003e /etc/apt/sources.list.d/jessie-backports.list"]}}" }, { "v1Compatibility": "{"id":"460e9e88f2e3e275a94af3830c839674b2ca2af8140c1d46b1d60f7eb1ee00b5","parent":"98c8b00e72a3fefb671ae6a7a07c1f1ccd313c198f47cf98c33119ba0ef07688","created":"2017-01-17T00:49:51.939655817Z","container_config":{"Cmd":["/bin/sh -c apt-get update \u0026\u0026 apt-get install -y --no-install-recommends \t\tbzip2 \t\tunzip \t\txz-utils \t\u0026\u0026 rm -rf /var/lib/apt/lists/*"]}}" }, { "v1Compatibility": "{"id":"98c8b00e72a3fefb671ae6a7a07c1f1ccd313c198f47cf98c33119ba0ef07688","parent":"571c55696ed384dac735d9bd3d21f35d9c275ef40bef26dac50c6a0e3b5a8dd9","created":"2017-01-17T00:01:07.867997465Z","container_config":{"Cmd":["/bin/sh -c apt-get update \u0026\u0026 apt-get install -y --no-install-recommends \t\tbzr \t\tgit \t\tmercurial \t\topenssh-client \t\tsubversion \t\t\t\tprocps \t\u0026\u0026 rm -rf /var/lib/apt/lists/*"]}}" }, { "v1Compatibility": "{"id":"571c55696ed384dac735d9bd3d21f35d9c275ef40bef26dac50c6a0e3b5a8dd9","parent":"dd971d935f0529013f3bf48999e9cebe16e11f5318538fea15d61dd41326600a","created":"2017-01-17T00:00:45.363077258Z","container_config":{"Cmd":["/bin/sh -c apt-get update \u0026\u0026 apt-get install -y --no-install-recommends \t\tca-certificates \t\tcurl \t\twget \t\u0026\u0026 rm -rf /var/lib/apt/lists/*"]}}" }, { "v1Compatibility": "{"id":"dd971d935f0529013f3bf48999e9cebe16e11f5318538fea15d61dd41326600a","parent":"9f872f437c9c25c1364b6527e1570d990d5b935fe96f3aebf6acfcd5aa889500","created":"2017-01-16T20:35:16.587175871Z","container_config":{"Cmd":["/bin/sh -c #(nop) CMD [\"/bin/bash\"]"]},"throwaway":true}" }, { "v1Compatibility": "{"id":"9f872f437c9c25c1364b6527e1570d990d5b935fe96f3aebf6acfcd5aa889500","created":"2017-01-16T20:35:09.371844927Z","container_config":{"Cmd":["/bin/sh -c #(nop) ADD file:89ecb642d662ee7edbb868340551106d51336c7e589fdaca4111725ec64da957 in / "]}}" } ], "signatures": [ { "header": { "jwk": { "crv": "P-256", "kid": "K5CO:ZZ5X:DMFZ:MTEY:62K2:AHLT:GCMH:JHFI:4QVC:PHUT:BC7Q:HFM2", "kty": "EC", "x": "pnKfVj7NRAQwfowPYvaFKrAHgCYdbHuzuH7xxSpQ2Ds", "y": "fwTbqPdjEXNsC4L1XR7VoQ2o0Xhznn3562lOdFF_aeo" }, "alg": "ES256" }, "signature": "XDlym6XfYzkaRryxti-DiGykWFTXSo02VRy5Fa67a4R7dvgYX2OXVWfr3R8oxiUFiWP8N4Jz8nEHynySO0b3QA", "protected": "eyJmb3JtYXRMZW5ndGgiOjEyMjMyLCJmb3JtYXRUYWlsIjoiQ24wIiwidGltZSI6IjIwMTgtMDQtMThUMTA6MTE6NDRaIn0" } ] }