困扰我多日的registry的问题今天终于解决了,已经可以上传到内网的私有仓库了。
实验准备:
centos7.2+dockers1.9+registry V2.0
首先安装docker1.9
yum install docker
修改dockers配置文件添加OPTIONS=‘--insecure-registry localhost:5000‘设置本地仓库
# /etc/sysconfig/docker
# Modify these options if you want to change the way the docker daemon runs
OPTIONS=‘--selinux-enabled‘
OPTIONS=‘--insecure-registry localhost:5000‘
DOCKER_CERT_PATH=/etc/docker
启动docker
systemctl start docker
关闭防火墙
systemctl stop firewalld
获取最新版的registry
docker run -d -p 5000:5000 registry:2
至此本地registry仓库搭建完毕
在另外的docker主机上修改docker配置文件添加
/etc/sysconfig/docker
OPTIONS=‘--insecure-registry 192.168.55.22:5000‘
使用tag命令创建tag
docker tag 28e524afdd05 192.168.55.22:5000/centos
docker push 192.168.55.22:5000/centos
The push refers to a repository [192.168.55.22:5000/centos] (len: 1)
28e524afdd05: Pushed
2ebc6e0c744d: Pushed
latest: digest: sha256:f69cb10f28791c35cb5c4bcef8ae9d2050b494a0a7ce933e2dd75f21eff78d32 size: 6262
已经上传成功,可以在企业中将所有的docker主机修改docker配置即可。
从私有registry中获取镜像
docker pull 192.168.55.22:5000/centos
Using default tag: latest
Trying to pull repository 192.168.55.22:5000/centos ... latest: Pulling from centos
fa5be2806d4c: Pull complete
2ebc6e0c744d: Pull complete
044c0f15c4d9: Pull complete
28e524afdd05: Pull complete
Digest: sha256:f69cb10f28791c35cb5c4bcef8ae9d2050b494a0a7ce933e2dd75f21eff78d32
Status: Downloaded newer image for 192.168.55.22:5000/centos:latest
可以从私有仓库下载镜像完成。
最好在启动registry的时候使用 -v /opt/registry:/var/lib/registry 将registry的存储目录映射出来,即使docker容器没有了,仓库内容还都在。