Use the Docker registry image to create a private repository

  • 2020-06-12 11:32:37
  • OfStack

After installing Docker, you can simply set up a set of local private warehouse environments using the official registry image. This article documents the simple setup process.

Use registry to start the container for the private repository


docker run -d -p 5000:5000 -v /root/my_registry:/tmp/registry registry

Note: If no registry container has been installed before, an registry container will be automatically downloaded and started, creating a local private warehouse service. By default, the repository is created in the container's /tmp/registry directory, and the mirror file can be stored locally on the specified path using the -v parameter (for example, under the local directory /root/my_registry).

Mirror push to the private warehouse


docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04

Note: The registry container started according to Step 1 is the local container of the host host's IP and Port, push environment.


root@gerryyang:~# docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04 
The push refers to a repository [104.131.173.242:5000/ubuntu_sshd_gcc_gerry] (len: 1) 
Sending image list 
Pushing repository 104.131.173.242:5000/ubuntu_sshd_gcc_gerry (1 tags) 
511136ea3c5a: Image successfully pushed 
3b363fd9d7da: Image successfully pushed 
607c5d1cca71: Image successfully pushed 
f62feddc05dc: Image successfully pushed 
8eaa4ff06b53: Image successfully pushed 
894c0161121f: Image successfully pushed 
a45787b0222f: Image successfully pushed 
f0e3262ed661: Image successfully pushed 
Pushing tag for rev [f0e3262ed661] on {http://104.131.173.242:5000/v1/repositories/ubuntu_sshd_gcc_gerry/tags/14.04} 

The directory structure of the host my_registry


 root@gerryyang:~/my_registry# tree 
. 
 ├ ─ ─  images 
 │    ├ ─ ─  3b363fd9d7dab4db9591058a3f43e806f6fa6f7e2744b63b2df4b84eadb0685a 
 │    │    ├ ─ ─  ancestry 
 │    │    ├ ─ ─  _checksum 
 │    │    ├ ─ ─  json 
 │    │    └ ─ ─  layer 
 │    ├ ─ ─  511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 
 │    │    ├ ─ ─  ancestry 
 │    │    ├ ─ ─  _checksum 
 │    │    ├ ─ ─  json 
 │    │    └ ─ ─  layer 
 │    ├ ─ ─  607c5d1cca71dd3b6c04327c3903363079b72ab3e5e4289d74fb00a9ac7ec2aa 
 │    │    ├ ─ ─  ancestry 
 │    │    ├ ─ ─  _checksum 
 │    │    ├ ─ ─  json 
 │    │    └ ─ ─  layer 
 │    ├ ─ ─  894c0161121f105ac9b81bca7ac583ac1f29772625911db0fa2b6b475f5642fd 
 │    │    ├ ─ ─  ancestry 
 │    │    ├ ─ ─  _checksum 
 │    │    ├ ─ ─  json 
 │    │    └ ─ ─  layer 
 │    ├ ─ ─  8eaa4ff06b53ff7730c4d7a7e21b4426a4b46dee064ca2d5d90d757dc7ea040a 
 │    │    ├ ─ ─  ancestry 
 │    │    ├ ─ ─  _checksum 
 │    │    ├ ─ ─  json 
 │    │    └ ─ ─  layer 
 │    ├ ─ ─  a45787b0222f955d68d9db34fb18033144b8a78015d9e306a1613894da0fd86e 
 │    │    ├ ─ ─  ancestry 
 │    │    ├ ─ ─  _checksum 
 │    │    ├ ─ ─  json 
 │    │    └ ─ ─  layer 
 │    ├ ─ ─  f0e3262ed6617896b306852c923e4c0e1d359b58b29a02ef849c4b8978c73c65 
 │    │    ├ ─ ─  ancestry 
 │    │    ├ ─ ─  _checksum 
 │    │    ├ ─ ─  json 
 │    │    └ ─ ─  layer 
 │    └ ─ ─  f62feddc05dc67da9b725361f97d7ae72a32e355ce1585f9a60d090289120f73 
 │      ├ ─ ─  ancestry 
 │      ├ ─ ─  _checksum 
 │      ├ ─ ─  json 
 │      └ ─ ─  layer 
 └ ─ ─  repositories 
   └ ─ ─  library 
     └ ─ ─  ubuntu_sshd_gcc_gerry 
       ├ ─ ─  _index_images 
       ├ ─ ─  tag_14.04 
       └ ─ ─  tag14.04_json 
 
12 directories, 35 files 

Question on https


root@gerryyang:~# docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04 
FATA[0002] Error: Invalid registry endpoint https://104.131.173.242:5000/v1/: Get https://104.131.173.242:5000/v1/_ping: EOF. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 104.131.173.242:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/104.131.173.242:5000/ca.crt  

Solutions:

Modify the Docker configuration file


vim /etc/default/docker

Add the following 1 line


DOCKER_OPTS="$DOCKER_OPTS --insecure-registry=104.131.173.242:5000"

Restart Docker


sudo service docker restart

3 Private warehouse query method


curl http://104.131.173.242:5000/v1/search

Note: Use curl to view the mirror in warehouse 104.131.173.242:5000. In the results, you can see ubuntu_sshd_gcc_gerry, indicating that the upload was successful.


gerryyang@mba:personal_repository$curl http://104.131.173.242:5000/v1/search 
{"num_results": 0, "query": "", "results": []} 
gerryyang@mba:personal_repository$curl http://104.131.173.242:5000/v1/search 
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/ubuntu_sshd_gcc_gerry"}]} 

Access and download the private warehouse image on another machine


docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04
0

docker push 104.131.173.242:5000/ubuntu_sshd_gcc_gerry:14.04
1

Related articles: