Docker introduction private notes build docker private warehouse docker official warehouse

Posted by en on Thu, 10 Mar 2022 10:27:41 +0100

Two common image warehouses:

  • Docker official warehouse registry
  • VMware's open source warehouse harbor (built-in registry)

Docker's official image warehouse is an application based on http protocol deployed in the container.
The deployment and use methods are as follows:

The official image warehouse of Docker is deployed in the registry container. Find and download the container image:

[root@k8s-master /data]# docker search registry
NAME                                 DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
registry                             The Docker Registry 2.0 implementation for s...   2725                [OK]                
distribution/registry                WARNING: NOT the registry official image!!! ...   58                                      [OK]
stefanscherer/registry-windows       Containerized docker registry for Windows Se...   27                                      
budry/registry-arm                   Docker registry build for Raspberry PI 2 and...   18                                      

The first image marked OFFICIAL is downloaded:

[root@k8s-master /data]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
c87736221ed0: Pull complete 
1cc8e0bb44df: Pull complete 
54d33bcb37f5: Pull complete 
e8afc091c171: Pull complete 
b4541f6d3db6: Pull complete 
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@k8s-master /data]# 
[root@k8s-master /data]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
registry            latest              f32a97de94e1        7 months ago        25.8MB

Start a container using this image:

[root@k8s-master /data]# docker run -d --name docker-registry -p 5000:5000 registry
c9ab1fae9c2a3dc8da48cbce5ec3cd0e9e8f227af6aa1395448db88a17cbc7bb
[root@k8s-master /data]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                          NAMES
c9ab1fae9c2a        registry            "/entrypoint.sh /etc..."   8 seconds ago       Up 5 seconds        0.0.0.0:5000->5000/tcp                         docker-registry

Create configuration file daemon JSON (the file does not exist by default), add the private warehouse address:

vim /etc/docker/daemon.json

The configuration is as follows:

{
"registry-mirrors":["https://tdimi5ql.mirror.aliyuncs.com"],
"insecure-registries":["http://192.168.100.151:5000"]
}

Restart docker service:

systemctl daemon-reload
systemctl restart docker

It is found that after restarting the service, the warehouse (container registry) does not start automatically and needs to be started manually:

docker start docker-registry

Label the image you want to submit to the warehouse:

[root@k8s-master /data]# docker tag app/jenkins 192.168.100.151:5000/app/jenkins
[root@k8s-master /data]# docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
192.168.100.151:5000/app/jenkins   latest              83644f08fe7a        6 hours ago         660MB
app/jenkins                        latest              83644f08fe7a        6 hours ago         660MB

In practice, it is found that the effect of labeling is to add a REPOSITORY repository or an image with different image names in the image list. The IDs of the two images are exactly the same, indicating that they are the same image.

Next, submit the image to the remote image warehouse:

[root@k8s-master /data]# docker push 192.168.100.151:5000/app/jenkins
The push refers to repository [192.168.100.151:5000/app/jenkins]
559f4ae0e0c6: Pushed 
fd685e9a5043: Pushed 
cfdb476660b4: Pushed 
318ee23a3d4a: Pushed 
8cb2f467d731: Pushed 
2cfb7a3b4cb2: Pushed 
8fd6d61d388e: Pushed 
aeb2f97d8c7a: Pushed 
fcbb61c1c668: Pushed 
b55cd0cf7e45: Pushed 
917d7f6fc72d: Pushed 
b4a4159a6c4a: Pushed 
8bf46d2e80f6: Pushed 
877b494a9f30: Pushed 
latest: digest: sha256:fc58c06b0ff6ab1cbe895aa48ab8921e7fac1629aabba442fc9e3f4a7d818561 size: 3247

Next, verify that the image can be downloaded from the remote warehouse.

First delete the local image that has been submitted to the warehouse. Note that the image name should be used for deletion. If an id is used for deletion, an error will be reported because the same id corresponds to two image names (or there are two images with different labels pointing to the same id):

[root@k8s-master /data]# docker rmi 83644f08fe7a
Error response from daemon: conflict: unable to delete 83644f08fe7a (must be forced) - image is referenced in multiple repositories

Correct operation:
The image name (REPOSITORY) should be used for the first deletion. At this time, you can see that the prompt returned is to cancel the label and not really delete the image. The reason mentioned above is that there is another label pointing to the image id:

[root@k8s-master /etc/docker]# docker rmi app/jenkins
Untagged: app/jenkins:latest

The id can be used for the second deletion. Of course, the image name can also be used. At this time, the image is really deleted:

[root@k8s-master /data]# docker rmi 192.168.100.151:5000/app/jenkins
Untagged: 192.168.100.151:5000/app/jenkins:latest
Untagged: 192.168.100.151:5000/app/jenkins@sha256:fc58c06b0ff6ab1cbe895aa48ab8921e7fac1629aabba442fc9e3f4a7d818561
Deleted: sha256:83644f08fe7a5b137269dcde4132bd1ddd3cebb785cdc63ca018d8b88c33847d
Deleted: sha256:50f47b580b31fb1ec8b2e36ed19230d7cc5518ea26559e2364630b3e3b202864
Deleted: sha256:50eea350fc0f273c8f900deb83141d965ce8289eba7c3840795261e47d3d4323
Deleted: sha256:89602543224d192f0d224755a8b5c63ff9c3928ab3495d680c218cd76cddf48a
Deleted: sha256:cbdbf0f481551f918ad0a235f0ecf6897022493b759fc9ff564c2b33db7dfede

Try to pull the image just deleted from the warehouse and view it:

[root@k8s-master /data]# docker pull 192.168.100.151:5000/app/jenkins
Using default tag: latest
latest: Pulling from app/jenkins
d8d02d457314: Already exists 
5ae2c4acbc0f: Already exists 
9d30c820b1f2: Already exists 
5c50e57b98c7: Already exists 
eebefd700a88: Already exists 
c0a6323f718e: Already exists 
07fd7191c06d: Already exists 
146c19a74bc8: Already exists 
c015e8b53603: Already exists 
cf7384c89894: Already exists 
da96a327dec8: Already exists 
b79fb209b1a1: Already exists 
9dac0f3f7b2b: Already exists 
8478f3dea98b: Pull complete 
Digest: sha256:fc58c06b0ff6ab1cbe895aa48ab8921e7fac1629aabba442fc9e3f4a7d818561
Status: Downloaded newer image for 192.168.100.151:5000/app/jenkins:latest
[root@k8s-master /data]# 
[root@k8s-master /data]# 
[root@k8s-master /data]# docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
192.168.100.151:5000/app/jenkins   latest              83644f08fe7a        7 hours ago         660MB

Topics: Docker Container