daemon.json 是镜像库使用的闸门,必须将私有镜像库地址写入其中,否则就无法 pull 或 push 镜像。

准备一个用于实验的镜像:192.168.100.151:5000/mycentos

[root@k8s-master /data]# docker tag centos 192.168.100.151:5000/mycentos
[root@k8s-master /data]# docker images
REPOSITORY                         TAG                             IMAGE ID            CREATED             SIZE
192.168.100.151:5000/mycentos      latest                          67fa590cfc1c        2 months ago        202MB
centos                             latest                          67fa590cfc1c        2 months ago        202MB

daemon.json 中没有镜像库 192.168.100.151:5000 这个地址,所以 push 镜像失败:

[root@k8s-master /data]# cat /etc/docker/daemon.json 
{
"registry-mirrors":["https://tdimi5ql.mirror.aliyuncs.com"],
"insecure-registries":["http://192.168.100.151:80"]
}
[root@k8s-master /data]# docker pull 192.168.100.151:5000/mycentos
Using default tag: latest
Error response from daemon: Get https://192.168.100.151:5000/v2/: http: server gave HTTP response to HTTPS client

在 /etc/docker/daemon.json 中重新添加私有库地址 http://192.168.100.151:5000 并重启 docker 服务让配置生效:

[root@k8s-master /data]# cat /etc/docker/daemon.json 
{
"registry-mirrors":["https://tdimi5ql.mirror.aliyuncs.com"],
"insecure-registries":["http://192.168.100.151:80"],
"insecure-registries":["http://192.168.100.151:5000"]
}
[root@k8s-master /data]# systemctl restart docker.service

再次 push 镜像成功:

[root@k8s-master /data]# docker push 192.168.100.151:5000/mycentos
The push refers to repository [192.168.100.151:5000/mycentos]
877b494a9f30: Mounted from app/jenkins 
latest: digest: sha256:a36b9e68613d07eec4ef553da84d0012a5ca5ae4a830cf825bb68b929475c869 size: 529

验证:先将本地镜像 192.168.100.151:5000/mycentos 删除:

[root@k8s-master /data]# docker rmi 192.168.100.151:5000/mycentos
Untagged: 192.168.100.151:5000/mycentos:latest
Untagged: 192.168.100.151:5000/mycentos@sha256:a36b9e68613d07eec4ef553da84d0012a5ca5ae4a830cf825bb68b929475c869
[root@k8s-master /data]# 
[root@k8s-master /data]# docker images
centos                             latest                          67fa590cfc1c        2 months ago        202MB

重新 pull 该镜像:

[root@k8s-master /data]# docker pull 192.168.100.151:5000/mycentos
Using default tag: latest
latest: Pulling from mycentos
Digest: sha256:a36b9e68613d07eec4ef553da84d0012a5ca5ae4a830cf825bb68b929475c869
Status: Downloaded newer image for 192.168.100.151:5000/mycentos:latest
192.168.100.151:5000/mycentos:latest
[root@k8s-master /data]# 
[root@k8s-master /data]# docker images
REPOSITORY                         TAG                             IMAGE ID            CREATED             SIZE
192.168.100.151:5000/mycentos      latest                          67fa590cfc1c        2 months ago        202MB
centos                             latest                          67fa590cfc1c        2 months ago        202MB

可以发现,重新 pull 的镜像 id 跟原来一样


逆熵流
10 声望5 粉丝

终身学习,向上生长~