[Cloud native] Docker private warehouse registry

 

 

Table of contents

1) Use the docker container to run the registry private warehouse service.

2) Run the private warehouse service

3) Rename the image (the name of the image to be uploaded needs to indicate the ip of the private warehouse)

4) Edit the docker configuration file (because the default is to pull the official image of docker, which needs to be re-specified)

5) Other dockerhosts upload private warehouses

Modify the docker configuration file

View which mirrors are in the warehouse


1) Use the docker container to run the registry private warehouse service.

Note: registry is an official packaged service with a port of 5000, just like other virtual web services

Note that here we are using the registry:2 version, and there is a registry mirror, there is no big difference between the two. registry: is written in Python language, and registry:2 is written in Go language . In theory, this version of registry:2 runs faster.

命令:

docker pull registry:2

2) Run the private warehouse service

Order:

docker run -itd --name registry --restart=always -p 5000:5000 -v /registry:/var/lib/registry registry:2

-v:  挂载目录。  宿主机的目录(如果没有此目录会自动创建):容器内的目录。(数据卷:实现容器与宿主机之间的共享,通过一个目录"卷")
--restart=always:随着docker服务的启动而启动此容器

3) Rename the image (the name of the image to be uploaded needs to indicate the ip of the private warehouse)

Because the private image we use, when uploading or downloading, we need to rename the name of the image directly, and indicate the IP address of its private warehouse: exposed port. Remember that it is necessary, otherwise the warehouse will not be recognized and the upload or download will fail.

格式为:docker tag IMAGE[:TAG] [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG] 
命令:

docker tag nginx:latest 192.168.8.10:5000/nginx

4) Edit the docker configuration file (because the default is to pull the official image of docker, which needs to be re-specified)

#初次上传命令:
docker push 192.168.8.10:5000/nginx  #上传私有仓库会报错
#以下是报错:
#The push refers to repository [192.168.8.10:5000/nginx]
#Get https://192.168.8.10:5000/v2/: http: server gave HTTP response to HTTPS client

// The reasons for uploading the image failure are as follows:

Because docker downloads images from dockehub by default, you need to specify the IP and port of the private warehouse locally, because Docker does not allow non-HTTPS methods to push images by default. If this step is not done, an HTTPS error will be reported.

#Edit the configuration file of docker, specify the private warehouse address

vim /usr/lib/systemd/system/docker.service
修改:
[Service]
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.8.10:5000  
#修改完成之后重新加载docker和重启
systemctl daemon-reload
systemctl restart docker
#再次上传测试
docker push 192.168.8.10:5000/nginx:v1

Local dockerhost view private warehouse image method: enter the shared directory of the private warehouse

cd /registry/docker/registry/v2/repositories/
ls

5) Other dockerhosts upload private warehouses

Note here that since it is a private warehouse, it must be considered that multiple DockerHosts share it. If other DockerHosts want to use a private warehouse, you only need to modify the docker configuration file and specify the IP and port of the private warehouse. Of course, don’t forget, after changing the configuration file, daemon-reload , restart the docker service.

Modify the docker configuration file
vim /usr/lib/systemd/system/docker.service
[Service]
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.8.10:5000  
systemctl daemon-reload
systemctl restart docker.service
docker info
#看到私仓ip即为成功
 Insecure Registries:
 192.168.8.10:5000
 127.0.0.0/8
View which mirrors are in the warehouse
curl -XGET http://192.168.8.10:5000/v2/_catalog
  -X/--request  指定什么命令
  -G/--get 以get的方式来发送数据
  -E/--cert cert[:passwd] 客户端证书文件和密码 (SSL)
  -T/--upload-file  上传文件
curl http://localhost:5000/v2/_catalog      #查看本地私有仓库镜像
curl http://192.168.8.10:5000/v2/nginx/tags/list
{"name":"nginx","tags":["latest"]} //并看到详细的自定义 版本号

Guess you like

Origin blog.csdn.net/weixin_53678904/article/details/131947427