Installation of the Docker private repository

1.Registry

The official Docker Hub is a great place to manage public images, find the images we want, and push our own. However, sometimes our usage scenarios require that we have a private mirror repository to manage our own images. This can be done through the open source software Registry.

Registry has two copies of the code on Github: the old code base and the new code base. The old code was written in Python, had pull and push performance issues, and was deprecated after release 0.9.1. From version 2.0 to the development of the new code base, the new code base is written in go language, the generation algorithm of image ID, the preservation structure of the image on Registry has been modified, and the efficiency of pull and push image has been greatly optimized.

The registry image (details) is officially provided on Docker Hub. We can directly use the Registry image to build a container and build our own private warehouse service. The Registry image with the latest Tag is version 0.9.1, so we go straight to version 2.1.1.

2. The Registry deployment

2.1 Obtaining a Registry Image

Docker pull registry: 2.1.1Copy the code

2.2 Starting the Registry Image

[root@node1 bin]# docker run - d - v/opt/data/registry: / var/lib/registry - p, 5000:5000 - restart = always - name registry registry: 2.1.1
Copy the code

By default, Registry will save the uploaded image in the /var/lib/Registry of the container. We mount the /opt/data/ Registry directory of the host to this directory, so that the image can be saved to the /opt/data/ Registry directory of the host

2.3 Checking the Startup Status

2.4 After the Register service is started, use a Browser to access 192.168.44.201:5000/v2

3. Upload the image to the private repository

3.1 Adding a tag(centos:7.5.1804 = local image)

Docker tag centos: 7.5.1804 192.168.44.201:5000 / centos: 7.5.1804Copy the code

3.2 push

Docker push 192.168.44.201:5000 / centos: 7.5.1804Copy the code

Because Docker interacts with Docker Registry using HTTPS by default after 1.3.X, but the private repository set up here only provides HTTP service, so the following error will be reported when interacting with the private repository:

To solve this problem, we need to add the startup parameter when starting Docker Server to use HTTP access by default. Modify the Docker startup configuration file:

[root@node1 bin]# vim /usr/lib/systemd/system/docker.service[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target  firewalld.service Wants=network-online.target [Service] Type=notify# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --insecure -- registry 192.168.44.201:5000
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
Copy the code

Then restart Docker

systemctl daemon-reload
systemctl start docker 
Copy the code

And then push again, and it works

3.3 Viewing the Browser

4. View information about private warehouses

4.1 Images of private repositories

[root@node1 bin]# curl http://192.168.44.201:5000/v2/_catalog
{"repositories": ["centos"]}
[root@node1 bin]# 
Copy the code

4.2 Viewing Tag Information about an Image

[root@node1 bin]# curl http://192.168.44.201:5000/v2/centos/tags/list
{"name":"centos"."tags": ["7.5.1804"."7.5.1804.2"]}
[root@node1 bin]# 
Copy the code

5. Delete the image from the private repository

5.1 Downloading Resources

curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/delete_docker_registry_image.py | sudo tee /usr/local/bin/delete_docker_registry_image >/dev/null
Copy the code
chmod +x  /usr/local/bin/delete_docker_registry_image
Copy the code

5.2 Setting Environment Variables

[root@node1 bin]# export REGISTRY_DATA_DIR='/opt/data/registry/docker/registry/v2/'
Copy the code

This is because the environment variable REFISTRY_DATA_DIR is required in delete_docker_registry_image

5.3 remove the image

[root@node1 bin]# delete_docker_registry_image -- image centos: 7.5.1804.2
Copy the code

Deletion succeeded!!