Docker 创建私有仓库并使用
创建仓库:
[root@langzi01 /]# docker run -d -p 5000:5000 registry
Unable to find image 'registry:latest' locally
Trying to pull repository docker.io/library/registry ...
latest: Pulling from docker.io/library/registry
169185f82c45: Pull complete
046e2d030894: Pull complete
188836fddeeb: Pull complete
832744537747: Pull complete
7ceea07e80be: Pull complete
Digest: sha256:870474507964d8e7d8c3b53bcfa738e3356d2747a42adad26d0d81ef4479eb1b
Status: Downloaded newer image for docker.io/registry:latest
f51ab3c2bb7fce684f3e0b3de7a78a4b3d5a6020a2acbf2cae8e788605267760
查看
[root@langzi01 tmp]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f51ab3c2bb7f registry "/entrypoint.sh /e..." 2 minutes ago Up 2 minutes 0.0.0.0:5000->5000/tcp agitated_roentgen
注:docker默认的仓库镜像信息在/tmp中,所以在启动仓库时用这个目录,可以使用-v参数来修改,命令如下
[root@langzi01 tmp]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp registry
执行:
[root@langzi01 tmp]# docker pull tomcat
[root@langzi01 tmp]# docker tag tomcat:latest 127.0.0.1:5000/tomcat
[root@langzi01 tmp]# docker push 127.0.0.1:5000/tomcat
报错:https://xxx.xxx.xxx.xxx:5000/v1/_ping: http: server gave HTTP response
解决办法:
[root@langzi01 tmp]# echo '{ "insecure-registries":["127.0.0.1:5000"] }' > /etc/docker/daemon.json
[root@langzi01 tmp]# systemctl restart docker
再次上传本地镜像到仓库:
[root@langzi01 docker]# docker push 127.0.0.1:5000/tomcat
The push refers to a repository [127.0.0.1:5000/tomcat]
9a69d1970703: Layer already exists
54b63532b965: Layer already exists
8bf71984452f: Layer already exists
2a26f9e31825: Layer already exists
a6414350cc66: Layer already exists
73a5184b491e: Layer already exists
699c7914defb: Layer already exists
8be692af5632: Layer already exists
578414b395b9: Layer already exists
abc3250a6c7f: Layer already exists
13d5529fd232: Layer already exists
latest: digest: sha256:751898078f660f2570d65b2c55f6a3f71f3944d5f716b43b82372db9927ba4bc size: 2626
查看:
[root@langzi01 docker]# curl '127.0.0.1:5000/v2/_catalog'
{"repositories":["tomcat"]}