Docker container - build a local private warehouse

Table of contents

1. Overview of Registry

1. First download the registry image

 2. Add the address of the private image warehouse to the daemon.json file and restart

3. Create a registry container and open the port

4. Tag the image and upload it to the private warehouse

5. Get the private warehouse list and check whether the upload is successful.

         6. Verification: Download the image from the private warehouse


1. Overview of Registry

Docker officially provides an image registry for building a private warehouse. It is ok to run the container of the image and expose the 5000 port to the outside world. Usually the images we pull in docker are obtained from public warehouses such as docker hub or quay.io. In actual work, if every company uses docker, it must build its own private warehouse. Then we will build our own private warehouse through the registry image provided by docker.

1. First download the registry image

docker pull registry

 2. Add the address of the private image warehouse to the daemon.json file and restart

vim /etc/docker/daemon.json 
"insecure-registries": ["192.168.109.11:5000"],
"registry-mirrors": ["https://f1jd7jnk.mirror.aliyuncs.com"]

systemctl daemon-reload
systemctl restart docker.service

3. Create a registry container and open the port

docker create -it registry /bin/bash
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
'//-p指定端口,一内一外;-v表示挂载,前者是宿主机,后者是容器'

4. Tag the image and upload it to the private warehouse

The image must be tagged before uploading, otherwise it will go to the public repository by default.

#打标签
docker tag nginx:latest 192.168.127.130:5000/nginx
上传
docker push 192.168.127.130:5000/nginx
#删除原有镜像
docker rmi 192.168.127.130:5000/nginx:latest 
#查看镜像
docker images 
#从本地仓库下载镜像
docker pull 192.168.127.130:5000/nginx
#查看镜像
docker images

5. Get the private warehouse list and check whether the upload is successful.

curl -XGET http://192.168.127.130:5000/v2/_catalog
 
'//若成功会返回以下值'
{"repositories":["nginx"]}

6. Verification: Download the image from the private warehouse

#删除原有镜像
docker rmi 192.168.127.130:5000/nginx:latest 
#查看镜像
docker images 
#从本地仓库下载镜像
docker pull 192.168.127.130:5000/nginx
#查看镜像
docker images

 

Guess you like

Origin blog.csdn.net/weixin_71429844/article/details/127412245