1.docker pull registry
https://hub.docker.com/_/registry/
2.启动registry
docker run -d -p 5000:5000 -v /root/dodata:/var/lib/registry --restart=always registry
把一个image名字重新打上新的tag
docker tag hello2:latest 192.168.1.103:5000/hello2:latest
3.重启docker服务加上--insecure-registry
nohup docker -H unix:///var/run/docker.sock --insecure-registry 192.168.1.103:5000 -d &
4.push images到新的registry:docker push 192.168.1.103:5000/hello2
[root@rhel64-64bit dodata]# docker push 192.168.1.103:5000/hello2
The push refers to a repository [192.168.1.103:5000/hello2] (len: 1)
3490818497c9: Image already exists
83f0de727d85: Image already exists
882673a3c694: Image successfully pushed
Digest: sha256:87e0e1a9d821d04ba5e1c1842b5e819d5039a6d2e7cb29eacb7a01af3f671da5
[root@rhel64-64bit hello2]# pwd
/root/dodata/docker/registry/v2/repositories/hello2
curl http://192.168.1.103:5000/v2/_catalog
[root@rhel64-64bit hello2]# curl http://192.168.1.103:5000/v2/_catalog
{"repositories":["hello2"]}
curl http://192.168.1.103:5000/v2/hello2/tags/list
[root@rhel64-64bit hello2]# curl http://192.168.1.103:5000/v2/hello2/tags/list
{"name":"hello2","tags":["latest"]}
5.删除image
[root@rhel64-64bit hello2]# docker rmi 192.168.1.103:5000/hello2
Untagged: 192.168.1.103:5000/hello2:latest
重新从新的registry拉取镜像:
docker pull 192.168.1.103:5000/hello2
[root@rhel64-64bit hello2]# docker pull 192.168.1.103:5000/hello2
latest: Pulling from 192.168.1.103:5000/hello2
882673a3c694: Already exists
83f0de727d85: Already exists
3490818497c9: Already exists
Digest: sha256:87e0e1a9d821d04ba5e1c1842b5e819d5039a6d2e7cb29eacb7a01af3f671da5
Status: Downloaded newer image for 192.168.1.103:5000/hello2:latest
搭建需要认证的私有库:
1.docker run --entrypoint htpasswd registry -Bbn youser yo123456 > /root/auth/htpasswd
[root@rhel64-64bit ~]# docker run --entrypoint htpasswd registry -Bbn youser yo123456 > /root/auth/htpasswd
[root@rhel64-64bit ~]# cd auth
[root@rhel64-64bit auth]# ll
total 4
-rw-r--r-- 1 root root 69 May 17 00:50 htpasswd
2.把之前的registry的container删除,然后重新启动
docker run -d -p 5000:5000 --restart=always -v /root/dockdata:/var/lib/registry -v /root/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry
[root@rhel64-64bit auth]# docker run -d -p 5000:5000 --restart=always -v /root/dockdata:/var/lib/registry -v /root/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry
cd31265a6ee34c545611a58918e06f529c37d3238a5b9137ea611e86b20ef424
3.登录私有registry
docker login -u youser -p yo123456 192.168.1.103:5000
root@rhel64-64bit auth]# docker login 192.168.1.103:5000
Username: youser
Password:
Email:
WARNING: login credentials saved in /root/.docker/config.json
Login Succeeded
4.push images到私有库
[root@rhel64-64bit auth]# docker push 192.168.1.103:5000/hello2
The push refers to a repository [192.168.1.103:5000/hello2] (len: 1)
3490818497c9: Image already exists
83f0de727d85: Image already exists
882673a3c694: Image successfully pushed
Digest: sha256:87e0e1a9d821d04ba5e1c1842b5e819d5039a6d2e7cb29eacb7a01af3f671da5
[root@rhel64-64bit auth]#
curl --basic --user youser:yo123456 http://192.168.1.103:5000/v2/_catalog
[root@rhel64-64bit auth]# curl --basic --user youser:yo123456 http://192.168.1.103:5000/v2/_catalog
{"repositories":["hello2"]}
[root@rhel64-64bit auth]# curl --basic --user youser:yo123456 http://192.168.1.103:5000/v2/hello2/tags/list
{"name":"hello2","tags":["latest"]}
5.退出:
docker logout 192.168.1.103:5000