Deploy the Docker distribution repository

 Environment preparation:

Download the docker yum file

# wget -O /etc/yum.repos.d/aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo 

 1. Install docker-distribution 

# yum install -y docker-distribution
# systemctl enable docker-distribution.service 
# systemctl start docker-distribution.service 
# netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
tcp6       0      0 :::5000                 :::*                    LISTEN     

 By default, the docker client is linked to the mirror warehouse built by itself and uses https. In order to use the http method, the configuration file needs to be modified (2 methods):

Method 1:

# vim /etc/docker/daemon.json 
{
  "insecure-registries":["workstation:5000"]
}

2nd method:

# vim /usr/lib/systemd/system/ docker.service #Add 1 line of startup parameters
   --insecure-registry=workstation: 5000 \        

# systemctl daemon-reload 
# systemctl restart docker

 2. Common operations of docker warehouse

1) List all current mirrors

# curl http://workstation:5000/v2/_catalog
 {"repositories":["busybox_1","nginx","wordpress"]}

2) List the currently specified mirror

# curl http://10.99.73.10:5000/v2/_catalog?n=100

3) Search for mirrors

# curl http://10.99.73.10:5000/v2/wordpress/tags/list
{"name":"wordpress","tags":["latest"]}

4) Confirm if the Registry is working properly 

5) Delete the mirror

The Docker repository supports the image deletion API in version 2.1, but this delete operation only deletes the image metadata, not the layer data. This problem was resolved in version 2.4, adding a garbage collection command to delete unreferenced layer data. However, there are some restrictions, the specific operation steps are as follows:

Start the repository container

$ docker run -d \
    -p 5000:5000 \
    --restart=always \
    --name registry \
    -v /data/:/var/lib/registry \
    -v /data/config.yml:/etc/docker/registry/config.yml \
    registry:2.4.1

It needs to be explained here that when starting the warehouse, the delete=true configuration item needs to be added to the storage configuration in the configuration file to allow deletion of the image. The following configuration file is used in this experiment:

version: 0.1
log:
  fields:
    service: registry
storage:
    delete:
        enabled: true
    cache:
        blobdescriptor: inmemory
    filesystem:
        rootdirectory: /var/lib/registry
http:
    addr: :5000
    headers:
        X-Content-Type-Options: [nosniff]
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3

View the data in the warehouse container, and use the du command to view the size. You can see that the current warehouse data size is 339M.

# du -sh /data/docker/registry/v2/
339M /data/docker/registry/v2/

The API corresponding to deleting an image is as follows: 

reference: The image corresponds to the sha256 value.

First look at the sha256 of the mirror to be deleted

# ls /data/docker/registry/v2/repositories/wordpress/_manifests/revisions/sha256/
4eefa1b7fdce1b6e6953ca18b6f49a68c541e9e07808e255c3b8cc094ff085da

perform delete operation

# curl -I -X DELETE http://workstation:5000/v2/wordpress/manifests/sha256:4eefa1b7fdce1b6e6953ca18b6f49a68c541e9e07808e255c3b8cc094ff085da
HTTP/1.1 202 Accepted
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
Date: Thu, 15 Dec 2016 06:27:19 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

perform garbage collection

命令:registry garbage-collect config.yml

# docker exec -ti registry bash
root@ef45a8a624c1:/# registry garbage-collect /etc/docker/registry/config.yml

Look at the data size

# du -sh /data/docker/registry/v2/
88K /data/docker/registry/v2/

It can be seen that the mirror data has been deleted, from 339M to 88K.

PS: I have tried to delete the image directly in the directory, and then restart the docker daemon, the image will also be deleted.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324669694&siteId=291194637