搭建docker registry私有镜像仓库
一、安装docker-distribution
yum install -y docker-distribution
安装完成后,启动服务:
systemctl enable docker-distribution.service
systemctl start docker-distribution.service
二、配置config.yaml
在/etc/docker-distribution/registry目录下编辑config.yaml文件如下:
[root@k8s-master docker]# vim /etc/docker-distribution/registry/config.yml
version: 0.1
log:
fields:
service: registry
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /var/lib/registry #可修改
http:
addr: 192.168.60.128:5000 # [仓库运行的IP地址]:[仓库运行的端口,可设为5000]
三、修改daemon.json
[root@k8s-master docker]# vim /etc/docker/daemon.json
{"insecure-registries": ["192.168.60.128:5000"]}
随后重启docker:
systemctl restart docker
这样就完成了私有仓库的搭建。
四、测试上传
用docker images查看已下载的镜像,选择一个,例如tomcat,打上标签:
docker tag [tomcat镜像的ID] [仓库IP]:[仓库端口]/tomcat
docker tag 29a4ec4a1572 192.168.60.128:5000/tomcat
之后,用docker push命令将打上标签后的镜像上传至私有仓库:
docker push [仓库IP]:[仓库端口]/tomcat
docker push 192.168.60.128:5000/tomcat
看到类似于下面这样的提示后,说明上传成功:
[root@k8s-master docker]# docker push 192.168.60.128:5000/tomcat
The push refers to a repository [192.168.60.128:5000/tomcat]
8a7dce73d7c4: Pushed
6da0dd6a6aec: Pushed
7ff9a7fd153d: Pushed
a3a8efb9d782: Pushed
d297a2eb5e16: Pushed
b92d80dc1874: Pushed
77b174a6a187: Pushed
latest: digest: sha256:b5fb7857a99f4583c067e2ce6cb1ce1a98a999a2cc15c0cd8a09998fa84557dc size: 1783
五、测试查询
Docker registry v2的API与v1差异非常大。例如,用下面的命令查看已上传的镜像:
curl -X GET http://仓库IP:仓库端口/v2/_catalog
[root@k8s-master docker]# curl -X GET http://192.168.60.128:5000/v2/_catalog
{"repositories":["tomcat"]}
搭建docker registry私有镜像仓库
一、安装docker-distribution
yum install -y docker-distribution
安装完成后,启动服务:
systemctl enable docker-distribution.service
systemctl start docker-distribution.service
二、配置config.yaml
在/etc/docker-distribution/registry目录下编辑config.yaml文件如下:
[root@k8s-master docker]# vim /etc/docker-distribution/registry/config.yml
version: 0.1
log:
fields:
service: registry
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /var/lib/registry #可修改
http:
addr: 192.168.60.128:5000 # [仓库运行的IP地址]:[仓库运行的端口,可设为5000]
三、修改daemon.json
[root@k8s-master docker]# vim /etc/docker/daemon.json
{"insecure-registries": ["192.168.60.128:5000"]}
随后重启docker:
systemctl restart docker
这样就完成了私有仓库的搭建。
四、测试上传
用docker images查看已下载的镜像,选择一个,例如tomcat,打上标签:
docker tag [tomcat镜像的ID] [仓库IP]:[仓库端口]/tomcat
docker tag 29a4ec4a1572 192.168.60.128:5000/tomcat
之后,用docker push命令将打上标签后的镜像上传至私有仓库:
docker push [仓库IP]:[仓库端口]/tomcat
docker push 192.168.60.128:5000/tomcat
看到类似于下面这样的提示后,说明上传成功:
[root@k8s-master docker]# docker push 192.168.60.128:5000/tomcat
The push refers to a repository [192.168.60.128:5000/tomcat]
8a7dce73d7c4: Pushed
6da0dd6a6aec: Pushed
7ff9a7fd153d: Pushed
a3a8efb9d782: Pushed
d297a2eb5e16: Pushed
b92d80dc1874: Pushed
77b174a6a187: Pushed
latest: digest: sha256:b5fb7857a99f4583c067e2ce6cb1ce1a98a999a2cc15c0cd8a09998fa84557dc size: 1783
五、测试查询
Docker registry v2的API与v1差异非常大。例如,用下面的命令查看已上传的镜像:
curl -X GET http://仓库IP:仓库端口/v2/_catalog
[root@k8s-master docker]# curl -X GET http://192.168.60.128:5000/v2/_catalog
{"repositories":["tomcat"]}