In addition to using Docker Hub, you can also create a virtual repository for your own needs. Here’s how to create a virtual repository under centos7. This article is based on the Docker-Registry v2.x version.

  1. Run the repository image by obtaining the official Registry image
$ docker run -d -p 5000:5000 --restart=always --name registry registry
Copy the code

The default container directory to create is /var/lib/registry. You can use the -v argument to store the image file in a local directory. For example, the following example puts the uploaded image into the local /home/data/registry directory.

$ docker run -d \
    -p 5000:5000 \
    -v /home/data/registry:/var/lib/registry \
    registry
Copy the code
  1. Push /pull is created as if there is a repository and it is running. You can push your image to the repository. Assume that the address of the repository is 192.168.103.22:5000. 2.1 Viewing the Local Mirror
$Docker Image Ls REPOSITORY TAG Image ID CREATED VIRTUAL SIZE Ubuntu latest ba5877dc9BEC 9 weeks ago 192.7 MBCopy the code

Using docker tag will ubuntu: latest this mirror marked 192.168.103.22:5000 / ubuntu: the latest.

$docker tag ubuntu: latest 127.0.0.1:5000 / ubuntu: latest $docker image ls REPOSITORY tag image ID CREATED VIRTUAL SIZE Ubuntu latest ba5877dc9bec 9 weekes line 192.7 MB 192.168.103.22:5000 / ubuntu: latest latest ba5877dc9bec 9 weekes line of 192.7 MBCopy the code

2.2 Upload image of tag using Docker push

$docker push 192.168.103.22:5000 / ubuntu: latest The push refers to The repository 192.168.103.22:5000 / ubuntu 373 a30c24545:  Pushed a9148f5200b0: Pushed cdd3de0940ab: Pushed fc56279bbb33: Pushed b38367233d37: Pushed 2aebd096e0e2: Pushed latest: digest: sha256:fe4277621f10b5026266932ddf760f5a756d2facd505a94d2da12f4f52f71f5a size: 1568Copy the code

2.3 curl View an image in the repository

$curl 127.0.0.1:5000 / v2 / _catalog {" repositories: "[]" ubuntu "}Copy the code

2.4 Pull the image on another host (assume IP address: 192.168.103.23) First create file /etc/docker-daemon. json at 192.168.103.23 and write the contents

{"insecure-registries": ["192.168.103.22:5000"]}Copy the code

Then restart the Docker

service docker restart
Copy the code