3

搭建私有docker镜像仓库

 2 years ago
source link: https://www.wencst.com/archives/511
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

搭建私有docker镜像仓库

作者: wencst 分类: linux,Uncategorized,微服务 发布时间: 2017-04-04 14:45 阅读: 1,622 次

centos6.5(已升级内核至3.10)

registry:2.1.1

对于docker公有镜像来说,大家一般都用hub.docker.com来存放镜像,并在此仓库中查找官方以及私人公开的一些镜像,但此仓库经常出现网速很慢,所以对于我们私有镜像来说,可以存放在私有镜像仓库,所以需要搭建一个私有的镜像仓库。

#docker pull registry:2.1.1

目前还没有找到lastest版本(或者我从官方下载时链接超时了),所以还需要加上这个版本号。

docker run -d -v /new/work/docker/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:2.1.1

–restart=always这个参数应该是用于重启的,即容器出现问题或关闭时自动重启,我这里启动时没加这个参数。

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
ecd2324364d9        registry:2.1.1      "/bin/registry /etc/   5 minutes ago       Up 5 minutes        0.0.0.0:5000->5000/tcp   registry

说明我们已经启动了registry服务,打开浏览器输入http://127.0.0.1:5000/v2,出现下面情况说明registry运行正常,

以haproxy为例,将镜像上传至私有仓库。

首先需要将镜像打标签

#docker tag haproxy 127.0.0.1:5000/haproxy

然后push镜像

#docker push 127.0.0.1:5000/haproxy

检查是否push成功,在网页中打开http://127.0.0.1:5000/v2/_catalog,显示如下即为成功

其他服务器中想要pull这个镜像,可以使用

#docker pull 127.0.0.1:5000/haproxy

偶尔会遇到无法push镜像到私有仓库,那是因为启动的私有镜像仓库registry不是可信赖的,需要添加如下代码至/etc/default/docker文件中

DOCKER_OPTS=”–insecure-registry xxx.xxx.xxx.xxx:5000″

然后重启docker

service docker restart

如果文章对您有用,扫一下支付宝的红包,不胜感激!

欢迎加入QQ群进行技术交流:656897351(各种技术、招聘、兼职、培训欢迎加入)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK