Build a Docker image warehouse

Build a Docker image warehouse

The image warehouse (Docker Registry) has two forms: public and private:

  • Public warehouse: For example, Docker’s official Docker Hub . There are also some domestic cloud service providers that provide public services similar to Docker Hub, such as NetEase Cloud Image Service , DaoCloud Image Service , Alibaba Cloud Image Service , etc.

  • In addition to using public repositories, users can also build private Docker Registry locally. The enterprise's own image is best implemented using a private Docker Registry. Building a mirror warehouse can be achieved based on the DockerRegistry officially provided by Docker.

1. Simplified version of the mirror warehouse

Docker's official Docker Registry is a basic version of the Docker image warehouse, which has complete functions of warehouse management, but does not have a graphical interface.

The construction method is relatively simple, the commands are as follows:

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

The command mounts a data volume registry-data to the /var/lib/registry directory in the container, which is the directory where the private image library stores data.

Visit http://你的ip:5000/v2/_catalogto view the images included in the current private image service

2. Version with graphical interface

Before pushing the image warehouse, you need to configure the warehouse address into the daemon.json file of the docker service and be trusted by docker.

2.1 Configure Docker trust address

The private server uses the http protocol, which is not trusted by Docker by default , so you need to make a configuration:

# 打开要修改的文件
vi /etc/docker/daemon.json

# 添加内容:"insecure-registries":["你的ip:8080"]
# 例如
"insecure-registries":["http://192.168.110.130:8080"]

# 重新加载
systemctl daemon-reload

# 重启docker
systemctl restart docker

2.2 Write docker-compose file

Use DockerCompose to deploy DockerRegistry with a graphical interface. The command is as follows:

version: '3.0'
services:
  registry:
    image: registry
    volumes:
      - ./registry-data:/var/lib/registry
  ui:
    image: joxit/docker-registry-ui:static
    ports:
      - 8080:80
    environment:
      - REGISTRY_TITLE=某某某的私有仓库
      - REGISTRY_URL=http://registry:5000
    depends_on:
      - registry

image-20230809162501759

2.2 Run and access

# 运行
# -d 为后台运行
docker-compose up -d

# 查看日志
docker-compose logs -f

你的ip:8080

For example

http://192.168.110.130:8080

image-20230809162122428
# 停止docker-compose
docker-compose down

3. Push or pull the image from the private image repository

Before pushing the local image to the warehouse, you must rename (docker tag) the image, prefixed with the image warehouse address.

Retag the local image, and the name prefix is ​​the address of the private warehouse: http://192.168.110.130:8080/

Tips: Here I have pulled the latest image of nginx and used this image as an example.

nginx:latestThe 192.168.110.130:8080/nginx:1.0same as the IMAGE ID, it is essentially the same image.

# 将nginx:latest tag为 192.168.110.130:8080/nginx:1.0
docker tag nginx:latest 192.168.110.130:8080/nginx:1.0

3.1 Push image

docker push 192.168.110.130:8080/nginx:1.0
image-20230809163904297

3.2 Pull the image

docker pull 192.168.110.130:8080/nginx:1.0

Guess you like

Origin blog.csdn.net/m0_60789072/article/details/132193113