Docker registry简介
运行registry
下载并运行registry
[root@centos ~]# docker run -d -p 5000:5000 -v ${PWD}/registry:/var/lib/registry --restart always --name registry registry:2.7.1Unable to find image 'registry:2.7.1' locally2.7.1: Pulling from library/registrycbdbe7a5bc2a: Pull complete47112e65547d: Pull complete
演示
构建一个本地registry仓库。
思路就是启动一个容器来作为registry仓库镜像存储镜像。
修改daemon.json
[root@centos ~]# cd /etc/docker/[root@centos docker]# lsdaemon.json key.json[root@centos docker]#[root@centos docker]# cat daemon.json{"registry-mirrors": ["https://s2nni63l.mirror.aliyuncs.com"]}
将加速器地址改成本地监听端口:
{"registry-mirrors": ["http://127.0.0.1:5000"]}
重启docker
[root@centos docker]# systemctl restart docker
浏览器查看
这里看到repositories为空,因为仓库里面没有什么。
将镜像打包,并push到registry
[root@centos docker]# docker tag nginx:1.17.9 127.0.0.1:5000/nginx:1.17.9[root@centos docker]# docker push nginx:1.17.9 127.0.0.1:5000/nginx:1.17.9"docker push" requires exactly 1 argument.See 'docker push --help'.Usage: docker push [OPTIONS] NAME[:TAG]Push an image or a repository to a registry[root@centos docker]# docker push 127.0.0.1:5000/nginx:1.17.9The push refers to repository [127.0.0.1:5000/nginx]351816b95c49: Pushed0e07021aa61a: Pushedb60e5c3bcef2: Pushed1.17.9: digest: sha256:30d9dde0c4cb5ab4989a92bc2c235b995dfa88ff86c09232f309b6ad27f1c7cd size: 948
浏览器查看restry
可以看到仓库中有nginx镜像了。
下次可以直接从自己构建的仓库去拉取镜像会快很多。
这次演示由于资源有限,全部在一台机器上搭建。
资源足够的话,可以用一台server来搭建registry,操作时类似的,存放好镜像,这样在同一局域网下面大家就可以公用这个仓库,提升拉取镜像速度了。
[root@centos docker]# docker pull 127.0.0.1:5000/nginx:1.17.91.17.9: Pulling from nginxDigest: sha256:30d9dde0c4cb5ab4989a92bc2c235b995dfa88ff86c09232f309b6ad27f1c7cdStatus: Image is up to date for 127.0.0.1:5000/nginx:1.17.9127.0.0.1:5000/nginx:1.17.9
