搭建docker本地私有仓库

一:准备工作如下:

1、建立相关文件夹:

[root@iZ28bi7khfvZ registry]# pwd
/laughing/registry
[root@iZ28bi7khfvZ registry]# ls
config.yml docker

2、上传配置文件config.yml至服务器/laughing/registry目录下,内容如下:

[root@iZ28bi7khfvZ registry]# vi config.yml

version: 0.1
log:
fields:
service: registry
storage:
delete:
enabled: true
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff] health:
storagedriver:
enabled: true
interval: 10s
threshold: 3

3、从官方仓库中pull下registry镜像:

docker pull registry

二:开始运行registry镜像

运行registry镜像时要挂载仓库目录,挂载配置文件,指定端口,如下:

docker run -d -p 5000:5000 -v /laughing/registry/:/var/lib/registry -v /laughing/registry/config.yml:/etc/docker/registry/config/yml –name registry –restart=always registry

运行上条指令后可看到registry容器已经启动啦:

[root@iZ28bi7khfvZ registry]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47602f950bf9 registry “/entrypoint.sh /etc…” 37 minutes ago Up 30 minutes 0.0.0.0:5000->5000/tcp registry

三:测试

例如将本地已有的镜像上传至仓库中:

将本地镜像打标签;

docker tag base:jdktomcat IP:5000/base:jdktomcat

然后推送到私有仓库中:

docker push IP:5000/base:jdktomcat

此时出现错误:http: server gave HTTP response to HTTPS client

因为docker与docker registry默认交互使用https,而我们搭建的私有仓库使用http服务

因此需要在服务器上配置如下:

vim /usr/lib/systemd/system/docker.service

找到ExecStart=/usr/bin/dockerd这一行 在后面追加  –insecure-registry IP:5000

保存后需要重启docker

systemctl daemon-reload

ststemctl restart docker.service

此时再次执行docker push IP:5000/base:jdktomcat

发现已可推送成功

通过查看仓库镜像来确认下:

[root@iZ28bi7khfvZ registry]# curl -get http://IP:5000/v2/_catalog
{“repositories”:[“base”]}

[root@iZ28bi7khfvZ registry]# curl -get http://IP:5000/v2/base/tags/list
{“name”:”base”,”tags”:[“jdktomcat”]}

至此我们已确认私有仓库搭建完成!

参考链接:https://www.cnblogs.com/Tempted/p/7768694.html