docker创建私有仓库

一、在服务端192.168.0.110上拉取仓库镜像:registry

[root@localhost ~]# docker pull registry 

 

二、在服务端192.168.1.110运行docker私有仓库

[root@localhost ~]# docker run -d -v /registry:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest

如果成功执行,则表示我们的docker私有仓库搭建成功。

说明:

/registry 表示宿主机目录,该目录如果不存在会自动创建。

docker -v 宿主机目录:容器目录(把宿主机的目录映射到容器中,防止docker私有仓库这个容器被删除时,仓库里的镜像也会被删除。)

 

三、在客户端制作镜像

1. 以hello-world为例,先把它拉取下来

[root@localhost ~]# docker pull hello-world

2. 给hello-world镜像打个tag,表示新的版本

[root@localhost ~]# docker tag hello-world 192.168.0.110:5000/hello-world:latest (蓝色部份是镜像名称,可以不要IP和端口)

3. 将新的hello-world镜像上传到私有仓库

[root@localhost ~]# docker push 192.168.0.110:5000/hello-world:latest

错误:

The push refers to a repository [192.168.1.161:5000/hello-world]

Get https://192.168.1.161:5000/v1/_ping: http: server gave HTTP response to HTTPS client

原因: docker私有仓库服务器,默认是基于https传输的,所以我们需要在客户端192.168.0.110做相关设置,不使用https传输

解决:

[root@localhost ~]# vi /etc/docker/daemon.json

将下面的代码放进去保存并退出。

"insecure-registries":["192.168.0.110:5000"]

最终如下所示:

{ "registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"], "insecure-registries":["192.168.0.110:5000"] }

依次执行下面两条命令,重新启动docker:

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

再次执行推送命令:

[root@localhost ~]# docker push 192.168.1.161:5000/hello-world:latest

 

4. 在私有仓库192.168.0.110查看上传的镜像

[root@localhost repositories]# ls /registry/docker/registry/v2/repositories

或者在客户端执行以下命令查看:

[root@localhost ~]# curl http://192.168.0.110:5000/v2/_catalog

会输出:

{"repositories":["hello-world"]}

私有仓库创建成功

 

四、在其它机器上pull

服务器上docker images:

 

拉取镜像:

[root@localhost docker]# docker pull 192.168.0.110:5000/tomcat-mybatis-xml:latest

 

启动: (启动的时候镜像名只是tomcat-mybatis-xml,不是192.168.0.110:5000/tomcat-mybatis-xml)

[root@localhost docker]# docker run --name tomcat-mybatis-xml -p 8080:8080 -d 192.168.0.110:5000/tomcat-mybatis-xml

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值