一、安装docker-ce
可参考https://www.jianshu.com/p/da6159384ac6的docker-ce安装部分
二、registry容器挂载源准备
mkdir -p /opt/docker/config
cat > /opt/docker/config/config.yml <<EOF
version: 0.1
log:
fields:
service: registry
storage:
delete:
enabled: true
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
EOF
三、拉取registry镜像并启动实例
docker pull registry
docker run -d -p 5000:5000 -v /opt/docker/data/registry:/var/lib/registry -v /opt/docker/config/config.yml:/etc/docker/registry/config.yml registry
四、开放http连接方式
Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报上面的错误。为了解决这个问题需要在启动docker server时增加启动参数为默认使用http访问。修改docker启动配置文件:
/usr/lib/systemd/system/docker.service
找到ExecStart并添加--insecure-registry 192.168.0.153:5000
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.0.153:5000
改完之后重启dcoker:
systemctl daemon-reload
systemctl restart docker
五、测试
服务端:
docker pull busybox
docker tag busybox localhost:5000/busybox
docker push localhost:5000/busybox
客户端:
docker pull IP地址:5000/busybox
删除镜像
curl -I -X DELETE http://localhost:5000/v2/busybox/manifests/sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649