Ubuntu18 build Docker Registry Services (rpm)

1. Download Mirror
First, we pull down the warehouse:

$ docker pull registry


2. Configure profile
default registry in the case does not support removing the mirror, we need to write the configuration file yourself, start time is mapped into the container, config.yml write files in the / data directory:

Note: The file must be separated by spaces, can not use the tab character.

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

Configuration can be started after the completion of the container, note the location config.yml mapping file:

$ docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry -v /data/config.yml:/etc/docker/registry/config.yml registry

Run curl -X GET localhost: 5000 / v2 / _catalog will be able to see all the mirrors in the registry:

$ curl -X GET localhost:5000/v2/_catalog


3. Configure host
host IP I installed Docker Registry service is 192.168.100.183, I now want to push mirrored in the host machine.

(1) Only default HTTPS protocol support Registry in connection the case, so first we want the host server trust Registry.

Edit the host file in /etc/docker/daemon.json, if not new:

{
  "Registry-Mirrors": [ "http://hub-mirror.c.163.com"],
  "in the insecure-Registries": [ "192.168.100.183:5000"]
}
Note that in the third row is specified in the Registry address of the server and port number Registry exposure.

(2) modify /lib/systemd/system/docker.service, loading profile

Add a line in the configuration file: EnvironmentFile = - / etc / docker / daemon.json

(3) Restart Docker Service

 

4. Upload mirror
our image upload hello-world example:

[wxs@bogon ~]$ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
nginx                       latest              5699ececb21c        7 days ago          109MB
portainer/portainer    latest              7afb7abcfe5f        8 days ago          57MB
rancher/server         stable              85b3b338d0be        4 weeks ago         1.08GB
hello-world              latest              e38bc07ac18e        2 months ago        1.85kB
rancher/agent          v1.2.10             6023e1a77132        3 months ago        237MB


(1) First, we modify the image you want to upload, name format is: Registry mirror server address name /: tag form.

Upcoming library / hello-world: latest amended as 192.168.100.183/hello-world:latest:

$ docker tag library/hello-world:latest 192.168.100.183:5000/hello-world:latest
$ docker images

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
nginx                                   latest              5699ececb21c        7 days ago          109MB
portainer/portainer                latest              7afb7abcfe5f        8 days ago          57MB
rancher/server                      stable              85b3b338d0be        4 weeks ago         1.08GB
192.168.100.183:5000/hello-world   latest              e38bc07ac18e        2 months ago        1.85kB
hello-world                          latest              e38bc07ac18e        2 months ago        1.85kB
rancher/agent                      v1.2.10             6023e1a77132        3 months ago        237MB


(2) Then push the mirror:

$ docker push 192.168.100.183:5000/hello-world

The Refers to the Push A Repository at The [192.168.100.183:5000/hello-world]
2b8cbd0846c5: Pushed 
Latest: Digest: sha256: d5c74e6f8efc7bdf42a5e22bd764400692cf82360d86b8c587a7584b03f51520 size: 524

(3) back to the Registry server, re-execute the command to view mirror:

$ curl -X GET localhost:5000/v2/_catalog

{ "repositories": [ "hello -world"]}

can see just the host has got uploaded image.

 

5. View command

We just used a API, see all the mirrors on the server Registry, namely / v2 / _catalog. There are other view commands, as follows:

Mirroring a list of all Tag: 
/ v2 / image name / tags / list, such as: / v2 / hello-world / tags / list

Details of a tag list 
/ v2 / image name / manifests / tag number, such as: / v2 / hello-world / manifests / latest

Get a tag's Digest 
curl --header "the Accept: the Application / vnd.docker.distribution.manifest.v2 + json" the -I -X the HEAD 192.168.100.183:5000/v2/hello-world/manifests/latest

 

6. Remove the mirror
to remove the mirror need to specify the image name and digest (obtained during upload), use the following command:

DELETE / v2 / image name / manifests / Mirror digest

$ curl -I -X DELETE localhost:5000/v2/hello-world/manifests/sha256:d5c74e6f8efc7bdf42a5e22bd764400692cf82360d86b8c587a7584b03f51520

The HTTP / 1.1 202 Accepted
Docker-Distribution's of Api-Version-: Registry / 2.0
X--the Content-the Type-the Options: nosniff
a Date: Wed, 04 Jul-2018 06:49:17 GMT
the Content-the Length: 0
the Content-the Type: text / Plain ; charset = utf-8

representatives HTTP 202 successful re-view mirror and TAG, has shown removed:

$ curl -X GET localhost:5000/v2/_catalog

{"repositories":["hello-world"]}

$ curl -X GET localhost:5000/v2/hello-world/tags/list

{ "name": "hello- world", "tags": null}
but in fact only logical deletes files still exist, if you want to completely remove the need for garbage collection.

 

7. Go to the Registry internal service:

docker exec -it 9d4d2055fb3a sh
execute the command:

registry garbage-collect /etc/docker/registry/config.yml

 


Original: https: //blog.csdn.net/yuanlaijike/article/details/80912801 

Guess you like

Origin www.cnblogs.com/helios-fz/p/10932303.html