Docker private repository management and deletion of images in local repositories

Docker private repository management and deletion of images in local repositories

1: Docker private warehouse installation

1. Download the image from the image repository:

[root@localhost ~]# systemctl start docker

#If there is already an image, the way to force delete the original image is as follows:
[root@xxx-pub /]# docker rmi -f docker.io/registry
Untagged: docker.io/registry:latest
Untagged: docker.io/registry@sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8
[root@xxx-pub /]#

#Start downloading the latest image.
[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
4064ffdc82fe: Pull complete 
c12c92d1c5a2: Pull complete 
4fbc9b6835cc: Pull complete 
765973b0f65f: Pull complete 
3968771a7c3a: Pull complete 
Digest: sha256:20bbbc0f6384cf7dc6e292ccbe75935b73c92ec776543c970904bc60feceb129
Status: Downloaded newer image for registry:latest
[root@localhost ~]#

2. Start and mount the image repository to the local disk:

[root@xxx-pub /]# docker run -d -v /registry:/home/docker-registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest
Unable to find image 'registry:latest' locally
Trying to pull repository docker.io/library/registry ... 
latest: Pulling from docker.io/library/registry
Digest: sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8
Status: Downloaded newer image for docker.io/registry:latest
b7bd2b14ed488936afe798be95f3cd56f604fb092d45cf6f4a58359bcad0d34c
[root@xxx-pub /]#
  • -v /registry:/home/docker-registry: By default, the repository is stored in the /home/docker-registry directory in the container, and the specified local directory is mounted to the container.
  • -p 5000:5000 : port mapping. That is, the local port 5000 is mapped to the port 5000 in the registry.
  • –restart=always1: Always restart the container when it exits. Mainly used in production environments.
  • –privileged=true: The security module selinux in CentOS7 disables permissions. The parameter adds privileges to the container. If you do not add privileges when uploading the image, a similar permission error will be reported. OSError: [Errno 13] Permission denied: '/tmp/registry/repositories/liibrary') or (Received unexpected HTTP status: 500 Internal Server Error)
  • –name registry: Specifies the name of the container.

To persist data, mount the volume to /home/docker-registry

3. We tag a local image and upload it:

Check which local images are available:

[root@xxx-pub /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos centos7.5.1804 fdf13fa91c6e 4 weeks ago 200 MB
docker.io/registry latest b2b03e9146e1 2 months ago 33.3 MB
[root@xxx-pub /]#

Take docker.io/centos as an example.

[root@xxx-pub /]# docker tag fdf13fa91c6e localhost:5000/xxx-centos7.5.1804:1.0
##localhost:5000 represents the warehouse address, fdf13fa91c6e represents the images id, xxx-centos7.5.1804 represents the image name, and 1.0 represents the version number.

or:
[root@xxx-pub /]# docker tag docker.io/centos:centos7.5.1804 localhost:5000/xxx-centos7.5.1804:1.0

4. Direct upload:

[root@xxx-pub /]# docker push localhost:5000/xxx-centos7.5.1804:1.0
The push refers to a repository [localhost:5000/xxx-centos7.5.1804]
bcc97fbfc9e1: Pushed 
1.0: digest: sha256:7c14180942615fef85cb5c8b1388e028be1a8f79694a5fa30a4025173e42ad61 size: 529
[root@xxx-pub /]#

During the PUSH process, an error similar to the following may be reported (the following is the error prompt on the Internet):

[root@localhost ~]# docker push 192.168.174.128:5000/hello:latest
The push refers to a repository [192.168.174.128:5000/hello]
Unable to ping registry endpoint https://192.168.174.128:5000/v0/
v2 ping attempt failed with error: Get https://192.168.174.128:5000/v2/: http: server gave HTTP response to HTTPS client
 v1 ping attempt failed with error: Get https://192.168.174.128:5000/v1/_ping: http: server gave HTTP response to HTTPS client
[root@localhost ~]#

Solution:

Using https, modify the /etc/sysconfig/docker (here is the docker under Centos7) file, add ADD_REGISTRY='--add-registry 192.168.18.162:5000', INSECURE_REGISTRY='--insecure-registry 192.168.18.162:5000' (the above is the configuration of the historical docker version), as shown below:

However, in the configuration of the new docker container repository, the configuration in your own docker container is adopted (the following configuration is specified here on both the docker registry and the machine where the other pull image is pulled):

After the specification is completed, restart Docker. The restart configuration is as follows:

[root@youx-pub volumes]# systemctl restart docker

In addition: Check docker.service and the configuration file:

[root@youx-pub registry]find / -name docker.service
/sys/fs/cgroup/memory/system.slice/docker.service
/sys/fs/cgroup/devices/system.slice/docker.service
/sys/fs/cgroup/blkio/system.slice/docker.service
/sys/fs/cgroup/cpu,cpuacct/system.slice/docker.service
/sys/fs/cgroup/pids/system.slice/docker.service
/sys/fs/cgroup/systemd/system.slice/docker.service
/usr/lib/systemd/system/docker.service
[root@youx-pub registry]# vim /usr/lib/systemd/system/docker.service 


Then execute:

#Because the docker.service file that can be used for systemctl startup has changed, the following configuration must be performed. Then execute the docker restart work systemctl daemon-reload
systemctl restart docker

If the following error is still reported:

[root@youx-pub registry]# docker push 192.168.18.162:5000/nginx:1.2
The push refers to a repository [192.168.18.162:5000/nginx]
Get https://192.168.18.162:5000/v1/_ping: http: server gave HTTP response to HTTPS client
[root@youx-pub registry]#

The solution is:

Create daemon.json under /etc/docker with the following content:

{"insecure-registries":["192.168.18.162:5000"]}

Then restart the Docker container:

[root@youx-pub volumes]# systemctl restart docker

5. After the upload is complete, we can check whether there is an image in the mounted directory:

[root@xxx-pub docker-registry]# pwd
/home/docker-registry
[root@xxx-pub docker-registry] # ls /registry/
Docker

6. About viewing local images:

[root@xxx-pub docker-registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["xxx-centos7.5.1804","xxx-centos7.5.1804-v1.0"]}
[root@xxx-pub docker-registry]#

7. Seeing that there are two images, we need to obtain their tag information for downloading:

[root@xxx-pub docker-registry]# curl http://192.168.18.162:5000/v2/xxx-centos7.5.1804/tags/list
{"name":"xxx-centos7.5.1804","tags":["1.0"]}
[root@xxx-pub docker-registry]#

8. Then we download the image directly (to another computer):

[root@bigdata2 ~]# docker pull 192.168.18.162:5000/youx-centos7.5.1804:1.0
Using default tag: latest
Trying to pull repository 192.168.18.162/youx-centos7.5.1804 ... 
Get https://192.168.18.162/v1/_ping: dial tcp 192.168.18.162:443: getsockopt: no route to host
[root@bigdata2 ~]#

If the above situation occurs, the solution is:

Compile:

[root@youx-pub volumes]# vim /etc/containers/registries.conf this file.
The old one is to edit: /etc/sysconfig/docker


Then restart docker

[root@youx-pub volumes]# systemctl restart docker

Then I found that I could pull

#Note that the address here is: warehouse address: warehouse port number/REPOSITORY:TAG
[root@bigdata2 ~]# docker pull 192.168.18.162:5000/youx-centos7.5.1804:1.0 

If it still doesn't work, you need to modify /etc/docker/daemon.json, the content is as follows:

[root@bigdata2 docker]# cat daemon.json 
{"insecure-registries":["192.168.18.162:5000"]}

2. Upload the image from another machine to the docker image repository:

[root@bigdata2 ~]# docker tag centos7-jdk8-nginx:1.0 192.168.18.162:5000/centos7-jdk8-nginx:1.0
[root@bigdata2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.18.162:5000/centos7-jdk8-nginx 1.0 bcacd65e2a2e 2 minutes ago 2.18 GB

[root@bigdata2 ~]# docker push 192.168.18.162:5000/centos7-jdk8-nginx:1.0
The push refers to a repository [192.168.18.162:5000/centos7-jdk8-nginx]
f018e9c38a66: Pushed 
2a47dcd341ef: Pushed 
c5dea3bc729a: Pushed 
bcc97fbfc9e1: Pushed 
1.0: digest: sha256:d907ff2f8eb590209700c01ce85c78d0bc778a4238539d747e4667d68cb52102 size: 1163
[root@bigdata2 ~]#

Then enter the location of the docker image warehouse:

[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["centos7-jdk8-nginx","nginx"]}
[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/centos7-jdk8-nginx/tags/list
{"name":"centos7-jdk8-nginx","tags":["1.0"]}
[root@youx-pub registry]#

3. How to delete the local image? Normally, the deletion function is not provided, so a third-party plug-in is used to delete it.

The location of the plugin on github:
https://github.com/burnettk/delete-docker-registry-image

1. Download resources

[root@master registry]# 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

sudo chmod a+x /usr/local/bin/delete_docker_registry_image 

2. Set relevant link variables:

Find REGISTRY_DATA_DIR, command:
[root@youx-pub registry]# find / -name registry
[root@youx-pub registry]# find / -name registry
/var/lib/docker/overlay2/d72320cd67b42f7ae66342cc6dedab7abe5e89106de8c4919ec8c5a6e5940b09/diff /var/lib/ucf/registry
/var/lib/docker/overlay2/92211417089f7be8239def550e1e89ce3f0e50ac57f2c36ba723ca312ea06ae3/diff/bin/registry
/var/lib/docker/overlay2/c1716aea0b380eb94ead9aa02552769acd4c3dac8e6dab735997f1709ce79a33/diff/etc/docker/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/diff/var/lib/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/bin/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/etc/docker/registry
/var/lib/docker/overlay2/46f719f01255c431b4343e78607341d6d66ea482bc6d03c3b4e05e7413f46be6/merged/var/lib/registry
/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry
/opt/data/registry
/registry
[root@youx-pub registry]#
Found [root@youx-pub repositories]# pwd
/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry/v2/repositories
[root@youx-pub repositories]# ls
centos7-jdk8-nginx nginx
[root@youx-pub repositories]#

So set the location of the image repository to:
[root@master registry]# export REGISTRY_DATA_DIR=/var/lib/docker/volumes/1522d54c954c755250cb71686cacd9714cd3d0f0c706ec18c1e490c7881fe713/_data/docker/registry/v2

The address is our mount address:

Take a look at the related tags:

[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["youx-centos7.5.1804","youx-centos7.5.1804-v1.0"]}
[root@youx-pub registry]# curl http://192.168.18.162:5000/v2/youx-centos7.5.1804-v1.0/tags/list
{"name":"youx-centos7.5.1804-v1.0","tags":["latest"]}
[root@youx-pub registry]#

We can delete it directly afterwards:

[root@master registry]# delete_docker_registry_image --image youx-centos7.5.1804-v1.0:latest

INFO [2017-04-08 11:39:39,793] Deleting /registry/docker/registry/v2/repositories/nginx/_manifests/tags/v1
Let's take a look at the mirror images of the local warehouse:

[root@master registry]# curl http://192.168.18.162:5000/v2/_catalog
{"repositories":["youx-centos7.5.1804"]}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • .NETCore Docker implements containerization and private image repository management
  • Analysis of Docker's method for creating local images
  • Briefly describe how to install Tomcat image and deploy web project in Docker
  • The simplest implementation of spring boot packaging docker image
  • How to generate a docker image and complete container deployment in a spring boot project
  • How to deploy Vue project using Docker image + nginx
  • Detailed explanation of the latest IDEA process of quickly deploying and running Docker images
  • Detailed explanation of the use of DockerHub image repository
  • Docker image management common operation code examples

<<:  Detailed explanation of the cache implementation principle of Vue computed

>>:  MySQL 5.7.19 installation and configuration method graphic tutorial (win10)

Recommend

Detailed Analysis of Event Bubbling Mechanism in JavaScript

What is bubbling? There are three stages in DOM e...

Native JS implements a very good-looking counter

Today I will share with you a good-looking counte...

js tag syntax usage details

Table of contents 1. Introduction to label statem...

Detailed explanation of gcc command usage under Linux system

Table of contents 1. Preprocessing 2. Compilation...

CSS3 category menu effect

The CSS3 category menu effects are as follows: HT...

In-depth analysis of MySQL execution plans

Preface In the previous interview process, when a...

5 ways to achieve the diagonal header effect in the table

Everyone must be familiar with table. We often en...

How to deploy MySQL master and slave in Docker

Download image Selecting a MySQL Image docker sea...

Detailed explanation of angular two-way binding

Table of contents Bidirectional binding principle...

OpenLayers realizes the method of aggregate display of point feature layers

Table of contents 1. Introduction 2. Aggregation ...

Introduction to the use of this in HTML tags

For example: Copy code The code is as follows: <...

Vue implements login jump

This article example shares the specific code of ...

mysql5.7.19 winx64 decompressed version installation and configuration tutorial

Recorded the installation tutorial of mysql 5.7.1...

How to use Baidu Map API in vue project

Table of contents 1. Register an account on Baidu...