前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >构建 Docker registry 私有镜像,解决docker私有仓库push出错问题

构建 Docker registry 私有镜像,解决docker私有仓库push出错问题

作者头像
周小董
发布2019-03-25 10:59:42
3.9K0
发布2019-03-25 10:59:42
举报
文章被收录于专栏:python前行者

适用于:Docker 1.8      环境:Centos7

每个版本的docker修改配置内容都不同,请大家看好安装的docker版本。

1)下载 docker registry私有镜像

代码语言:javascript
复制
docker pull docker.io/registry

2)修改配置文件

代码语言:javascript
复制
gedit /etc/sysconfig/docker

OPTIONS=’–selinux-enabled --insecure-registry 192.168.137.17:5000’

注:IP为修改的部分

3)从容器中启动Registry

代码语言:javascript
复制
docker run -d -p 5000:5000 --name registry -v /home/dockeruser/data:/tmp/registry  docker.io/registry

注:-d 表示该容器在后台运行

-p将主机的5000端口与容器的5000端口映射

–name 将容器的名称命名为registry

-v 表示将镜像的存储位置“/tmp/registry” 变更为宿主机的“/home/dockeruser/data”

注:这一步一定要在步骤2)之后,否则修改配置文件不会生效

4)在上传到私有的registry之前,需要指定新的Registry目的地址,需要在镜像名前加上

主机名和端口的前缀。

代码语言:javascript
复制
#docker images

找到要上传镜像的id,添加标签为192.168.137.17:5000/helloworld这种形式

代码语言:javascript
复制
docker tag id 192.168.137.17:5000/helloworld

注:192.168.137.17:5000 为所在主机的IP地址和端口

5)将打标签的镜像上传到私有库

代码语言:javascript
复制
docker push 192.168.137.17:5000/helloworld

显示信息如下:

代码语言:javascript
复制
The push refers to a repository [192.168.137.17:5000/node/helloworld] (len: 1)

Sending image list

Pushing repository 192.168.137.17:5000/node/helloworld (1 tags)
d8bd0657b25f: Image successfully pushed
Pushing tag for rev [df45579dbc81] on
{http://192.168.137.17:5000/v1/repositories/node/helloworld/tags/latest}

遇到问题:

The push refers to a repository [192.168.137.17:5000/node/helloworld] (len: 1) unable to ping registry endpoint https://192.168.137.17:5000/v0/ v2 ping attempt failed with error: Get https://192.168.137.17:5000/v2/: dial tcp 192.168.137.17:5000: connection refused v1 ping attempt failed with error: Get https://192.168.137.17:5000/v1/_ping: dial tcp 192.168.137.17:5000: connection refused

解决方案:

代码语言:javascript
复制
gedit /etc/sysconfig/docker

OPTIONS=’–selinux-enabled --insecure-registry 192.168.137.17:5000’

注:这一步一定要在创建私有仓库的容器之前【步骤2)】,否则修改配置文件不会生效

[root@node ~]# docker push 172.18.18.90:5000/busybox:v1 The push refers to repository [172.18.18.90:5000/busybox] Get https://172.18.18.90:5000/v2/: http: server gave HTTP response to HTTPS client

注意了,这是报错了,需要https的方法才能上传,我们可以修改下daemon.json来解决:

代码语言:javascript
复制
[root@node ~]# vim /etc/docker/daemon.json 
{
  "registry-mirrors": [ "https://registry.docker-cn.com"],
  "insecure-registries": [ "172.18.18.90:5000"]
}

添加私有镜像服务器的地址,注意书写格式为json,有严格的书写要求,然后重启docker服务:

代码语言:javascript
复制
[root@node ~]# systemctl  restart docker

参考: https://blog.csdn.net/chen798213337/article/details/51046175 https://www.linuxidc.com/Linux/2018-03/151308.htm

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年10月21日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器镜像服务
容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档