docker私人仓库

docker私人仓库
docker创建registry仓库

环境声明
centos7
docker镜像仓库:192.168.157.128
docker客户端:192.168.157.129

1、128搭建本地registry

[root@localhost ~]# docker pull registry
[root@localhost ~]# docker images
2、基于私有仓库镜像运行容器

[root@localhost ~]# docker run -d -p 5000:5000 -v /opt/registry:/tmp/registry docker.io/registry
[root@localhost ~]# docker ps -a
3、访问私有仓库

[root@localhost ~]# curl 127.0.0.1:5000/v1/search
{“num_results”: 0, “query”: “”, “results”: []} #私有仓库为空,没有提交新镜像到仓库中

网上都用这个curl 127.0.0.1:5000/v1/search,但是报404 page not found,后查证是v1版本的api查看方式,我们现在的版本是v2,所以用如下方法查看:

[root@localhost ~]# curl 127.0.0.1:5000/v2/_catalog
{“repositories”:[]} #私有仓库为空,没有提交新镜像到仓库中
4、从Docker Hub上下载一个ssh镜像

[root@localhost ~]# docker search -s 10 ssh
[root@localhost ~]# docker pull fedora/ssh
[root@localhost ~]# docker images
5、创建镜像链接或为基础镜像打个标签

[root@localhost ~]# docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh #库名不能有大写字母
[root@localhost ~]# docker images
6、修改Docker配置文件制定私有仓库url

[root@localhost ~]# vim /etc/docker/daemon.json 添加此行 不添加报错,https证书问题
{“insecure-registries”:[“192.168.157.128:5000”]}
[root@localhost ~]# service docker restart
7、提交镜像到本地私有仓库中

[root@localhost ~]# docker push 127.0.0.1:5000/ssh
8、查看私有仓库是否存在对应的镜像

扫描二维码关注公众号,回复: 1834453 查看本文章

[root@localhost ~]# curl 127.0.0.1:5000/v2/_catalog
从私有仓库中下载已有的镜像
1、登陆另外一台Docker客户端

[root@localhost ~]# ssh [email protected]
2、修改Docker配置文件

[root@localhost ~]# vim /etc/docker/daemon.json 不添加报错,https证书问题
{“insecure-registries”:[“192.168.157.128:5000”]}
[root@localhost ~]# service docker restart
3、查看私有仓库是否存在对应的镜像

[root@localhost ~]# curl 192.168.157.128:5000/v2/_catalog
[root@localhost ~]# curl 192.168.157.128:5000/v2/ssh/tags/list
4、从私有仓库中下载已有的镜像

[root@localhost ~]# docker pull 127.0.0.1:5000/ssh
[root@localhost ~]# docker images 验证是否下载成功

猜你喜欢

转载自blog.51cto.com/13587748/2135076