适用于:Docker 1.8,环境:Centos7
每个版本的docker修改配置内容都不同,请大家看好安装的docker版本。
1)下载 docker registry私有镜像
# docker pull docker.io/registry
2)修改配置文件
# gedit /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 192.168.137.17:5000'
注:红色IP为修改的部分
3)从容器中启动Registry
# 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目的地址,需要在镜像名前加上
主机名和端口的前缀。
#docker images node/helloworld
得到22d56cbd9e6
#docker tag 22d56cbd9e6 192.168.137.17:5000/node/helloworld
注:192.168.137.17:5000 为所在主机的IP地址和端口
5)将打标签的镜像上传到私有库
# docker push 192.168.137.17:5000/node/helloworld
显示信息如下:
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
a582cd499e0f: Image successfully pushed
3c3e582d88fa: Image successfully pushed
625e77fff1a8: Image successfully pushed
a00e4cef421d: Image successfully pushed
f543704611ec: Image successfully pushed
c32f3278cf8f: Image successfully pushed
5c88f029bcb1: Image successfully pushed
d3533bde148f: Image successfully pushed
6a06ae308acc: Image successfully pushed
9d1508e155f4: Image successfully pushed
f3c0db6d5143: Image successfully pushed
df45579dbc81: 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
解决方案:
# gedit /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 192.168.137.17:5000'
注:这一步一定要在创建私有仓库的容器之前【步骤2)】,否则修改配置文件不会生效。
吐槽:网上各种答案都有,确不说明docker是哪个版本。每个版本的docker修改配置内容都不同。