docker搭建本地仓库搭建和使用

不加密本地仓库:

搭建本地仓库,可以使其他主机在没有外部网络的情况下可以直接使用本机的仓库镜像

将registry包导入镜像仓库

[root@foundation17 docker]# docker load -i registry.tar 
f15ce52fc004: Loading layer [==================================================>] 196.8 MB/196.8 MB
c4fae638e7ce: Loading layer [==================================================>] 208.9 kB/208.9 kB
a4c5be5b6e59: Loading layer [==================================================>] 4.608 kB/4.608 kB
8693db7e8a00: Loading layer [==================================================>] 1.024 kB/1.024 kB
c75fbf48538e: Loading layer [==================================================>]   204 MB/204 MB
87c008f1a79b: Loading layer [==================================================>] 2.686 MB/2.686 MB
5a7b60cbc471: Loading layer [==================================================>]  2.56 kB/2.56 kB
81569492134a: Loading layer [==================================================>] 12.36 MB/12.36 MB
0aed6b236dec: Loading layer [==================================================>] 26.01 MB/26.01 MB
f3d8a78718d2: Loading layer [==================================================>] 55.81 kB/55.81 kB
32e4b1196a41: Loading layer [==================================================>] 1.024 kB/1.024 kB
15f0e3b29c8b: Loading layer [==================================================>] 1.024 kB/1.024 kB
4b0669413b8f: Loading layer [==================================================>] 1.024 kB/1.024 kB
07d93e41c370: Loading layer [==================================================>] 1.024 kB/1.024 kB

运行一个服务,开放本地500端口:

[root@foundation17 docker]# docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry registry
8615f19f7018ff41ce302fb48f406b54eba4591b216eac7bb3723b9c7b8dff39

将nginx包加进仓库:

[root@foundation17 docker]# docker tag nginx localhost:5000/nginx
[root@foundation17 docker]# docker push localhost:5000/nginx
The push refers to a repository [localhost:5000/nginx]
08d25fa0442e: Image successfully pushed 
a8c4aeeaa045: Image successfully pushed 
cdb3f9544e4c: Image successfully pushed 
Pushing tag for rev [c82521676580] on {http://localhost:5000/v1/repositories/nginx/tags/latest}

其他主机使用本地仓库:
以其他主机server1为例,在server1端将对westos.org的解析写入/etc/hosts文件中:

[root@server1 ~]# vim /etc/hosts
  8 172.25.17.5     server5
  9 172.25.17.6     server6
 10 172.25.17.250   westos.org

编辑/etc/docker/daemon.json 文件,或者直接将搭建仓库端的文件直接拷贝过来:

[root@server1 ~]# vim /etc/docker/daemon.json 

配置非加密模式:

  1 {
  2   "insecure-registries": ["westos.org:5000"]
  3 }

之后重启daemon和docker:

[root@server1 ~]# systemctl daemon-reload
[root@server1 ~]# systemctl start docker

在仓库foundation17端,将nginx重新打一个包push进本地仓库:

[root@foundation17 docker]# docker tag nginx westos.org:5000/nginx
[root@foundation17 docker]# docker push westos.org:5000/nginx
The push refers to a repository [westos.org:5000/nginx]
08d25fa0442e: Image successfully pushed 
a8c4aeeaa045: Already exists 
cdb3f9544e4c: Already exists 
Pushing tag for rev [c82521676580] on {http://westos.org:5000/v1/repositories/nginx/tags/latest}

在server1端就可以直接使用这个包了:

[root@server1 docker]# docker pull westos.org:5000/nginx
Using default tag: latest
Pulling repository westos.org:5000/nginx
c82521676580: Pull complete 
cdb3f9544e4c: Pull complete 
8f222b457ca6: Pull complete 
Status: Downloaded newer image for westos.org:5000/nginx:latest
westos.org:5000/nginx: this image was pulled from a legacy registry.  Important: This registry version will not be supported in future versions of docker.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值