关于docker:Docker-入门私人笔记十五回顾和总结2-daemonjson-控制镜像库的使用

47次阅读

共计 2197 个字符,预计需要花费 6 分钟才能阅读完成。

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 跟原来一样

正文完
 0