通过安装Docker后,Docker官网提供的registry镜像简单搭建一套本地私有仓库
1.通过registry镜像 ,做端口映射,创建一个容器,通过容器内的一个目录来创建私有仓库
并且将容器内仓库与本地路径做挂载
[root@node1 ~]# docker run -d -p 5000:5000 -v /opt/data/regostry/:/var/lib/registry registry:2
2. 将将要上传的镜像打tag,并push上传,发现出错
[root@node1 ~]# docker tag busybox:latest 192.168.37.21:5000/bysybox:v1
[root@node1 ~]# docker push 192.168.37.21:5000/busybox:v1
Error response from daemon: Get "https://192.168.37.21:5000/v2/": http: server gave HTTP response to HTTPS client
出错原因:docker上传下载默认只支持https协议,而搭建的私有仓库是http协议
解决办法:新建修改/etc/docker/daemon.json
[root@node1 ~]# cat /etc/docker/daemon.json
{"insecure-registries":["192.168.37.21:5000"]
}
并重启,docker重启后容器不运行,记得重启
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl restart docker
3.再push一下
[root@node1 ~]# docker push 192.168.37.21:5000/busybox:v1
The push refers to repository [192.168.37.21:5000/busybox]
95c4a60383f7: Layer already exists
v1: digest: sha256:db16cd196b8a37ba5f08414e6f6e71003d76665a5eac160cb75ad3759d8b3e29 size: 527[root@node1 ~]# ll /opt/data/regostry/docker/registry/v2/repositories/
total 4
drwxr-xr-x 5 root root 4096 Mar 9 20:57 busybox
通过registry-web来页面访问镜像仓库
[root@node1 ~]# docker run -d -p 8080:8080 --name registry-web --restart=always --link 1dbf0e13a218 -e registry_url=http://192.168.37.21:5000/v2 -e registry_name=localhost:5000 hyper/docker-registry-web:latest