How to build a private warehouse Docker

Private warehouse

Sometimes the use of such a public warehouse Docker Hub may be inconvenient, users can create a local repository for private use.

This section describes how to use local warehouse.

docker-registry is a tool provided by the official, the mirror can be used to build a private warehouse. Based on this article docker-registry v2.x version.

Installation and operation docker-registry

Container operation

You can get the official registry run by the mirror.

$ docker run -d -p 5000:5000 --restart=always --name registry registry

It will use the official registry to start mirroring private warehouse. By default, the warehouse will be created in the / var / lib / registry directory container. You can store the image file in the path specified by local -v parameter. For example, the following example will upload image into local / opt / data / registry directory.

$ docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry

Upload in private warehouses, search, download the image

After creating a private warehouse, you can use docker tag to mark a mirror, and then push it to the warehouse. Such as private warehouse address 127.0.0.1:5000.

First check has been mirrored in the machine.

$ docker image ls
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB

The use of docker tag ubuntu: latest this image is marked as 127.0.0.1:5000/ubuntu:latest.

Format docker tag IMAGE [: TAG] [REGISTRY_HOST [: REGISTRY_PORT] /] REPOSITORY [: TAG].

$ docker tag ubuntu:latest 127.0.0.1:5000/ubuntu:latest
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB
127.0.0.1:5000/ubuntu:latest latest ba5877dc9bec 6 weeks ago 192.7 MB

Use docker push to upload tagged image.

$ docker push 127.0.0.1:5000/ubuntu:latest
The push refers to repository [127.0.0.1:5000/ubuntu]
373a30c24545: Pushed
a9148f5200b0: Pushed
cdd3de0940ab: Pushed
fc56279bbb33: Pushed
b38367233d37: Pushed
2aebd096e0e2: Pushed
latest: digest: sha256:fe4277621f10b5026266932ddf760f5a756d2facd505a94d2da12f4f52f71f5a size: 1568

View warehouse mirroring curl.

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

Here you can see { "repositories": [ "ubuntu"]}, it indicates that the image has been successfully uploaded.

Delete an existing image, and then try to download the image from a private warehouse.

$ docker image rm 127.0.0.1:5000/ubuntu:latest

$ docker pull 127.0.0.1:5000/ubuntu:latest
Pulling repository 127.0.0.1:5000/ubuntu:latest
ba5877dc9bec: Download complete
511136ea3c5a: Download complete
9bad880da3d2: Download complete
25f11f5fb0cb: Download complete
ebc34468f71d: Download complete
2318d26665ef: Download complete

$ docker image ls
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
127.0.0.1:5000/ubuntu:latest latest ba5877dc9bec 6 weeks ago 192.7 MB

Precautions

If you do not want to use as a warehouse 127.0.0.1:5000 address, such as want others to host the network segment can also be pushed to mirror the private warehouse. You have to put this example 192.168.199.100:5000 network address as the address of a private warehouse, then you will find success not push mirror.

This is because the default does not allow non-HTTPS Docker way push mirror. We can cancel this restriction by Docker configuration options, or see the next section to configure a private warehouse that can be accessed over HTTPS.

(Verbatim)

Guess you like

Origin www.cnblogs.com/jiftle/p/11964186.html