Docker registry service localization

About 【Registry】

  • The official [Docker hub] is a good place to manage public mirrors. We can find the mirrors we want on it, or we can push our own mirrors up. However, sometimes, our usage scenarios require us to have a private mirror warehouse to manage our own mirrors. This can be achieved through the open source software Registry.
  • [Registry] There are two codes on github: old code base and new code base. The old code is written in python, and there are performance problems with pull and push. After the 0.9.1 version, it will be marked as deprecated (see more information = " https://github.com/docker/distribution ), and will not continue Development.
  • From version 2.0 to the development of the new code base, the new code base is written in go language, modified the generation algorithm of the mirror id, the storage structure of the mirror on the registry, and greatly optimized the efficiency of pull and push mirroring. 【Registry2.0】=》https://hub.docker.com/_/registry/

[What can the Regisry do?

  1. Strictly control where your images are being stored;
  2. Fully own your images distribution pipeline;
  3. Integrate image storage and distribution tightly into your in-house development workflow;

Note: About [Registry]'s official website introduction = " https://docs.docker.com/registry/

 

How to deploy Registry?

  • Download the registry image from [Docker Hub] = "The default version downloaded from the docker pull registry is docker.io/registry latest
  • Run the registry image to generate a container="docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest [Registry] The service will upload by default The image is saved in the /var/lib/registry of the container. Mount the /opt/registry directory of the host to this directory to save the image to the /opt/registry directory of the host.
  • View running containers = "docker ps / docker container ls If you view all, add parameter -a
  • If the registry container is up and running, enter [http://docker host ip:5000/v2/] in the browser to view, if the output = "{}, it means that the registry is running normally

[Test Registry]

  • Upload the image to the registry, first name the registry image of the host in a format that meets the requirements of the warehouse = "[registry_url:port/ImageName:tag]
--1.先标记镜像格式
docker tag nginx:latest localhost:5000/nginx:latest

--2.把标记格式的镜像推送到registy
docker push localhost:5000/nginx:latest

--注:localhost 为本地环境的ip地址;
  • View the list of all local mirrors 
docker images -a 或 docker image ls -a
  • Pull the image from the local registry

docker pull localhost:5000/nginx:latest

--注:localhost 为本地环境的ip地址;

At this step, there may be a problem that the image (push) cannot be pushed to the private warehouse, prompting:

The push refers to a repository [localhost:5000/nginx:latest]
The https://localhsot:5000/v2/: http:server gave HTTP response to HTTPS client

 1. The reason is that the registry service started locally is not safe and trustworthy;

 2. Solution, modify the client docker configuration file /etc/docker/daemon.json to add the registry service address

{
"registry-mirrors": [ "https://pee6w651.mirror.aliyuncs.com"],"insecure-registries": ["localhost:5000"]
}

--备注:
1.加速镜像设置 =》"registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com"] 是阿里云代理的Registry Hub仓库的地址,可以加快国内访问【Registry Hub】仓库的速度;
2.私有仓库镜像设置 =》"insecure-registries": ["localhost:5000"] 是本地【Registry】服务地址,localhost 为当前 docker 主机ip;

 3. [daemon.json] Storage path=" cd /etc/docker

 

 4. View/Edit daemon.json file configuration information=》 vi daemon.json

 5. Exit and save=》:wq

After the modification, restart the Docker service daemon.json configuration to take effect, execute the command=》systemctl restart docker, push again to succeed, check the local /opt/registry directory (or enter http://localhost:5000/v2/ in the browser) _catalog)

  • Or use the following command to view the mirror information in the local private warehouse
  1. curl -XGET http://registry:5000/v2/_catalog
  2. curl -XGET http://registry:5000/v2/image_name/tags/list

 

[Attachment: Mirror acceleration address]

  • Alibaba Cloud Image Accelerator=》https://help.aliyun.com/document_detail/60750.html
  • NetEase Cloud Mirror Accelerator=》https://hub-mirror.c.163.com
  • Official China Mirror Accelerator=》https://regisry.docker-cn.com
  • University of Science and Technology Mirror Accelerator=》https://docker.mirrors.ustc.edu.cn
  • Tsinghua Mirror Accelerator=》https://mirrors.tuna.tsinghua.edu.cn

The above steps have realized the process of deploying the Registry locally. Interested friends, hurry up and follow the small c teacher to implement it step by step! 

Guess you like

Origin blog.csdn.net/ChaITSimpleLove/article/details/105281751