いつも忘れるので備忘録:
概要
例えば以下のように nginx
イメージを pull
してプライべートレポジトリに push
すると、
[root@localhost ~]# docker pull nginx
[root@localhost ~]# docker tag docker.io/library/nginx myregistry.example.com/test-repo/nginx:latest
[root@localhost ~]# docker push myregistry.example.com/test-repo/nginx:latest
ローカルのコンテナイメージのダイジェストは IMAGE ID
にあるとおり、e4720093a3c1...
となっている。
[root@localhost ~]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
myregistry.example.com/test-repo/nginx latest e4720093a3c1 2 weeks ago 191 MB
docker.io/library/nginx latest e4720093a3c1 2 weeks ago 191 MB
[root@localhost ~]# docker inspect --format='{{.Id}}' myregistry.example.com/test-repo/nginx:latest
e4720093a3c1381245b53a5a51b417963b3c4472d3f47fc301930a4f3b17666a
しかしプライベートレポジトリ側のコンテナイメージのダイジェストを確認すると、ローカルとは異なり 30ddea...
となっている。
イメージを pull
する際もプライベートレポジトリ側のダイジェストを使用しなくてはならない。
/* ローカル側ダイジェストだと not found になる */
[root@localhost ~]# docker pull myregistry.example.com/test-repo/nginx@sha256:e4720093a3c1381245b53a5a51b417963b3c4472d3f47fc301930a4f3b17666a
Trying to pull myregistry.example.com/test-repo/nginx@sha256:e4720093a3c1381245b53a5a51b417963b3c4472d3f47fc301930a4f3b17666a...
WARN[0000] Failed, retrying in 1s ... (1/3). Error: initializing source docker://myregistry.example.com/test-repo/nginx@sha256:e4720093a3c1381245b53a5a51b417963b3c4472d3f47fc301930a4f3b17666a: reading manifest sha256:e4720093a3c1381245b53a5a51b417963b3c4472d3f47fc301930a4f3b17666a in myregistry.example.com/test-repo/nginx: unknown: artifact test-repo/nginx@sha256:e4720093a3c1381245b53a5a51b417963b3c4472d3f47fc301930a4f3b17666a not found
:
/* レポジトリ側のダイジェストを使用すれば問題ない */
[root@localhost ~]# docker pull myregistry.example.com/test-repo/nginx@sha256:30ddeabcda3d58fc6f46458dd202e381766eb37152719c1fd1b36cfafb8c18d6
Trying to pull myregistry.example.com/test-repo/nginx@sha256:30ddeabcda3d58fc6f46458dd202e381766eb37152719c1fd1b36cfafb8c18d6...
Getting image source signatures
Copying blob 0993b329f149 skipped: already exists
Copying blob 52f06d23eddc skipped: already exists
Copying blob 0dfc8eb18e7a skipped: already exists
:
原因
紛らわしいが、ローカルと Docker レポジトリ側ではそれぞれ別のダイジェストを使用(算出)しているので、この二つの値は必ずしも一致するものではないらしい。
#以下の github でも同様のことが議論されていた
https://github.com/docker/hub-feedback/issues/1925
そのため、イメージを push
した後にダイジェストで pull
する場合は実際のダイジェスト値をレポジトリ側で再確認する必要があり、ややこしい。
なお、一度レポジトリに push
したイメージを再度 pull
すれば ReepoDigests
を確認することでレポジトリ側のダイジェスト値を見ることができる。
/* いったんローカルは削除して再度 pull */
[root@localhost ~]# docker rmi e4720093a3c1
[root@localhost ~]# docker pull myregistry.example.com/test-repo/nginx:latest
:
[root@localhost ~]# docker inspect --format='{{index .RepoDigests}}' myregistry.example.com/test-repo/nginx
[myregistry.example.com/test-repo/nginx@sha256:30ddeabcda3d58fc6f46458dd202e381766eb37152719c1fd1b36cfafb8c18d6]