一.上传本地仓库镜像

1.拉取本地仓库工具镜像registry

  1. [root@localhost ~]# docker pull registry
  2. Using default tag: latest
  3. latest: Pulling from library/registry
  4. 79e9f2f55bf5: Pull complete
  5. 0d96da54f60b: Pull complete
  6. 5b27040df4a2: Pull complete
  7. e2ead8259a04: Pull complete
  8. 3790aef225b9: Pull complete
  9. Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
  10. Status: Downloaded newer image for registry:latest
  11. docker.io/library/registry:latest

2.运行一个Registry镜像仓库的容器实例

  1. [root@localhost ~]# docker run -itd --restart=always \
  2. > --name hwj-registry \
  3. > -p 8012:5000 \
  4. > -v /hwj-registry/registry:/var/lib/registry \
  5. > registry
  6. 9f009cefbf2b485243de92afe79291a4023e52b264b2f97953fdaa08634dbfab

3.查看当前仓库下的镜像

  1. [root@localhost ~]# curl 192.168.20.12:8012/v2/_catalog
  2. {"repositories":[]}

image.png

4.添加本地不安全的仓库信息

  1. [root@localhost ~]# vim /etc/docker/daemon.json
  2. [root@localhost ~]# cat /etc/docker/daemon.json
  3. {
  4. "insecure-registries": ["192.168.20.12:8012"],
  5. "registry-mirrors": ["https://dgodf4l3.mirror.aliyuncs.com"]
  6. }

5.重新加载Docker服务配置文件并重新启动docker

  1. [root@localhost ~]# systemctl daemon-reload
  2. [root@localhost ~]# systemctl restart docker

6.修改镜像标签(重命名)

  1. root@localhost ~]# docker tag 321 192.168.20.12:8012/mysql:v1.0
  2. [root@localhost ~]# docker images
  3. REPOSITORY TAG IMAGE ID CREATED SIZE
  4. 192.168.20.12:8012/mysql v1.0 3218b38490ce 3 months ago 516MB
  5. mysql latest 3218b38490ce 3 months ago 516MB
  6. registry latest b8604a3fe854 5 months ago 26.2MB

7.上传镜像

  1. [root@localhost ~]# docker push 192.168.20.12:8012/mysql:v1.0
  2. The push refers to repository [192.168.20.12:8012/mysql]
  3. d67a9f3f6569: Pushed
  4. fc8a043a3c75: Pushed
  5. 118fee5d988a: Pushed
  6. c654c2afcbba: Pushed
  7. 1d1f48e448f9: Pushed
  8. aad27784b762: Pushed
  9. 0d17fee8db40: Pushed
  10. d7a777f6c3a4: Pushed
  11. a0c2a050fee2: Pushed
  12. 0798f2528e83: Pushed
  13. fba7b131c5c3: Pushed
  14. ad6b69b54919: Pushed
  15. v1.0: digest: sha256:238cf050a7270dd6940602e70f1e5a11eeaf4e02035f445b7f613ff5e0641f7d size: 2828

8.查看本次仓库镜像

  1. [root@localhost ~]# curl 192.168.20.12:8012/v2/_catalog
  2. {"repositories":["mysql"]}

image.png

二.使用另一台主机测试拉取镜像

1.测试添加本地不安全的仓库信息

  1. [root@localhost ~]# cat /etc/docker/daemon.json
  2. {
  3. "insecure-registries": ["192.168.20.12:8012"],
  4. "registry-mirrors": ["https://dgodf4l3.mirror.aliyuncs.com"]
  5. }

2.重新加载Docker服务配置文件并重新启动docker

  1. [root@localhost ~]# systemctl daemon-reload
  2. [root@localhost ~]# systemctl restart docker

3.拉取镜像

  1. [root@localhost ~]# curl 192.168.20.12:8012/v2/_catalog
  2. {"repositories":["mysql"]}
  3. [root@localhost ~]# docker pull 192.168.20.12:8012/mysql:v1.0
  4. v1.0: Pulling from mysql
  5. 72a69066d2fe: Pull complete
  6. 93619dbc5b36: Pull complete
  7. 99da31dd6142: Pull complete
  8. 626033c43d70: Pull complete
  9. 37d5d7efb64e: Pull complete
  10. ac563158d721: Pull complete
  11. d2ba16033dad: Pull complete
  12. 688ba7d5c01a: Pull complete
  13. 00e060b6d11d: Pull complete
  14. 1c04857f594f: Pull complete
  15. 4d7cfa90e6ea: Pull complete
  16. e0431212d27d: Pull complete
  17. Digest: sha256:238cf050a7270dd6940602e70f1e5a11eeaf4e02035f445b7f613ff5e0641f7d
  18. Status: Downloaded newer image for 192.168.20.12:8012/mysql:v1.0
  19. 192.168.20.12:8012/mysql:v1.0
  20. [root@localhost ~]# docker images
  21. REPOSITORY TAG IMAGE ID CREATED SIZE
  22. nginx latest c316d5a335a5 2 months ago 142MB
  23. shenghuadehua/busybox v1.1 beae173ccac6 3 months ago 1.24MB
  24. 192.168.20.12:8012/mysql v1.0 3218b38490ce 3 months ago 516MB