Docker builds a local private warehouse

1. Build a local private warehouse

Sometimes it may be inconvenient to use public warehouses like Docker Hub. In this case, users can use registry to create a local warehouse for private use, which is similar to Maven's management.
There are many advantages to using a private repository:

1)节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库中下载即可;
2)提供镜像资源利用,针对于公司内部使用的镜像,推送到本地的私有仓库中,以供公司内部相关人员使用。

1. First download the registry image

docker pull registry

Docker officially provides a mirror registry (registration server) for building a private warehouse. You only need to download the mirror, run the container and expose port 5000, and you can use it

At present, Docker Registry has been upgraded to v2, and the latest version of Docker no longer supports v1. Registry v2 is written in Go language, has made many optimizations in terms of performance and security, and redesigned the storage format of the image. If you need to install registry v2, just download registry:2.2. Docker's official tool docker-registry can be used to build a private mirror warehouse

2. Add the private mirror warehouse address in the daemon.json file

vim /etc/ docker/daemon.json
{
"insecure-registries": ["192.168.2.200:5000"],
#添加,注意用逗号结尾
"registry-mirrors": ["https://6ijb8ubo.mirror.aliyuncs.com"]
}
systemctl restart docker.service


  

3. Run the registry container

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

==================================================== =
-itd: Open a pseudo terminal in the container for interactive operation, and run in the background

-v: Bind the /data/registry directory of the host to the container /var/lib/registry directory (this directory is the directory where mirror files are stored in the registry container) to achieve data persistence;

Start the private image warehouse in the container and mount the storage directory of the private warehouse to the specified directory of the host. The purpose of this is that if the container is deleted, the image stored in the container will not be deleted ( 默认情况下如果容器被删除,则存放于容器中的镜像也会丢失)

-p: Mapping port; accessing port 5000 of the host machine will access the service of the registry container

--restart=always: This is the restart strategy, always restart the container when the container exits

--name registry: Create a container named registry

registry:latest: This is the image that was pulled just now

==================================================== ==
The restart policy of the Docker container is as follows:

no: default policy, do not restart the container when the container exits

on-failure: When the container exits abnormally (exit status is not 0), the container will be restarted

on-failure:3 : Restart the container when the container exits abnormally, up to 3 times

always: Always restart the container when the container exits

unless-stopped: Always restart the container when the container exits, but does not consider containers that have been stopped when the Docker daemon starts

4. Label the image

docker tag centos:7 192.168.2.200:5000/centos:v1

If you do not name the private warehouse, the default is the public warehouse (docker hub), so you need to name the image.

Naming rules for private warehouse images:宿主机ip地址:端口号/xxxx(需要更改的名称)

Note: When you name the source image, the named image name is also regarded as a tag, because the id number is the same. If the source mirror is deleted, the named mirror will still exist, because a tag is deleted.  

5. Upload to private warehouse

docker push 192.168.2.200:5000/centos:v1

6. List all mirror images of private warehouse

curl http://192.168.2.200:5000/v2/_catalog

7. List the tags of the centos image of the private warehouse

curl http://192.168.2.200:5000/v2/centos/tags/list


 

8. Delete the original centos image first, and then test the private warehouse download

docker rmi -f 8652b9f0cb4c
docker pull 192.168.2.200:5000/centos:v1

Guess you like

Origin blog.csdn.net/weixin_69148277/article/details/131143633