1. Introduction of Registry Private Warehouse
When performing CICD in an enterprise, the application to be released needs to be imaged and pushed to the mirror warehouse for continuous deployment. At this time, it is definitely not convenient to push to the public mirror warehouse, so you need to build a private warehouse by yourself.
Fortunately , [Docker] officially has images of the Registry private repository, which makes it easy for us to build our own image repository based on containers.
2. Construction process
# Pull the latest version of the image docker pull registry:latest docker run -d -p 5000:5000 --restart=always --name myRegistry registry:latest # Mount the data volume to start the registry container # -v /mydata/docker-volume/registry/config/config.yml:/etc/docker/registry/config.yml Mount the data volume, specify the registry configuration file, pay attention to the host The config.yml with content must be prepared in advance in the corresponding directory, otherwise an error will be started # -v /mydata/docker-volume/registry/image:/var/lib/registry registry:latest Mount the data volume and specify the storage location of the private warehouse image docker run -d -p 5000 : 5000 --restart=always - -name myRegistry -v /mydata/docker-volume/registry/config/config.yml:/etc/docker/registry/config.yml -v /mydata/docker-volume/registry/image:/var/lib/registry registry :latest
The following is a default
version: 0.1 log: fields: service: registry storage: 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
3. Use the warehouse
In principle, all requests that can access the host where the mirror repository is located can use the Registry, as long as the specific server address is added before the mirror name.
- Upload local image to private repository
docker tag hello-world:latest localhost:5000/hello-world:latest docker push localhost:5000/hello-world:latest The push refers to repository [localhost:5000/hello-world] e07ee1baac5f: Pushed latest: digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 size: 525
We can see in the mounted mirror data volume
/mydata/docker-volume/registry/imagethat there is already storage mirror information, which verifies that the Push is indeed successful.
- Download images from private repositories to local
docker pull localhost:5000/hello-world:latest latest: Pulling from hello-world 2db29710123e: Pull complete Digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 Status: Downloaded newer image for localhost:5000/hello-world:latest localhost:5000/hello-world:latest docker tag localhost:5000/hello-world:latest hello-world:latest
Fourth, configure the warehouse
As above, a default version of the warehouse configuration file has been provided. In fact, the warehouse can also be configured for the following items, but I can’t use it yet, so I will make a record first and study it in detail when I have time.
- The version number, there is nothing to say about this, currently it is:
- log configuration
log: # Level selection debug, info, warn, error level : debug # log output format, optional text, json, logstash formatter : text # key-value pair added to the log to filter log fields : service: registry enviroment: staging
Hooks, parameters when sending by email when an exception occurs in the warehouse;
Storage options, you can configure image storage engines, local file systems, cloud storage services for major services, etc.;
Authentication options, optional silent, token, htpassword, etc.;
Notification options, there is a system that needs to be notified when an event occurs;
The redis option is used to cache files quickly;
Health monitoring options, configure to detect services to determine the status of the system;
Proxy option, configure the current registry as a Pull proxy to pull the Docker image from the remote official repository;
Verify options, limit the specified address to push the image;