Docker registry--to build a dedicated container warehouse

Source: Internet
Author: User
Tags auth dedicated server docker ps docker hub docker run etcd docker registry openstack swift

Preface

Under normal circumstances, if our computer in a networked environment, we can directly through the Docker pull images to obtain the relevant image, of course, this must be a networked environment, depending on the user's network speed or the size of the image has a different wait, If we were able to build a mirror repository like remote networking locally, and put our usual images in our own managed repositories, wouldn't it be possible to quickly get the image we wanted without waiting.


Docker Registry is the completion of building a local container warehouse, simply speaking a dedicated server as a mirrored warehouse, enabling a Docker registry container instance to provide services.

As shown in the figure above, We use the server 192.168.12.132 as a container warehouse, it should have one or two network cards, one can connect to the Internet, download at any time or we build the relevant Docker image, and then through another container connected network for distribution, the other host can quickly get the mirror image inside the warehouse.


Let's look at how to build our own container warehouse.

1, because we enable the Registry service is not secure and trustworthy, so we need to add the trusted parameters in all participating physical servers, specifically in the/etc/default/docker file, add the relevant parameters:--insecure-registry 192.168.12.132:5000

docker_opts= "-H 0.0.0.0:2375-h unix:///var/run/docker.sock--insecure-registry 192.168.12.132:5000"
Of course, any server that wants to be able to get mirrors from the container repository also needs to modify the relevant files and add the information as above.

Restarting the Docker service

Service Docker restart

2. Download the Docker registry image from the Docker hub and launch it to execute the following command

Docker run-d-v/root/registry:/var/lib/registry-p 5000:5000--restart=always--name Registry registry:2.3.0

root@controller:~# Docker run-d-v/root/registry:/var/lib/registry-p 5000:5000--restart=always--name Registry Regist ry:2.3.0
Unable to find image ' registry:2.3.0 ' locally
2.3.0:pulling from Library/registry
fdd5d7827f33: Pull complete
a3ed95caeb02:pull complete
a79b4a92697e:pull complete
1881c09fc734:pull
complete 0f24f5ab4e03:pull Complete
digest:sha256:5b6211cc1aa81916042ef0784ab8c8c2ce745f9dd851a67b2d80bf52a7f1c3c3
status:downloaded Newer image for registry:2.3.0
cf11bef3fc9dc5262d10797222dc3412433adf47de470350d15d1956df0b644c


The above command is to launch a registry:2.3.0 version of the mirror instance, if there is no local, need to download, registry service by default will upload the image stored in the container/var/lib/registry, we will host the/root/ The registry directory is mounted to this directory, which allows you to save the image to the host's/root/registry directory. The default registry port is 5000, and if the port is occupied you can replace other unoccupied ports.

Set the restart policy: Use the--restart parameter to set when using Docker run.
No-container does not restart
On-failure-container launch status non-0 o'clock restart
Always-restart all the Times

Then we can look at the Docker running status and the mirroring situation

root@controller:~# Docker images REPOSITORY TAG IMAGE ID CREATED SIZE                Swarm latest a180b24e38ed 4 weeks ago 19.34 MB Docker/ucp-proxy 1.1.1        354629dc8529 5 weeks ago 17.43 MB Docker/ucp-cfssl 1.1.1 3b3684098101 5 weeks ago 53.61 MB DOCKER/UCP latest 40fe8a8c618e 5 weeks ago 20.   Docker/ucp-auth 1.1.1 7b0a22fd86df 5 weeks ago 26.82 MB Docker/ucp-controller 1.1.1 C1ADA015CDB4 5 weeks ago 26.23 MB DOCKER/UCP-ETCD 1.1.1 Cb7711a7         FEA2 5 weeks ago 35.31 MB docker/ucp-compose 1.1.1 c6565efb4f69 5 weeks ago        58.61 MB Docker/ucp-auth-store 1.1.1 4fbf8982055b 5 weeks ago 57.78 MB Docker/ucp-swarm            1.1.1   7A1BCEDACF02 5 weeks ago 19.34 MB docker/ucp-dsinfo 1.1.1 782b4aca1228 7 Week                 S ago 68.51 mb ubuntu 14.04 b72889fa879c weeks ago 188 MB Registry 2.3.0 5eaced67751b 4 months ago 165.7 MB root@controller:~# Docker ps-a C                    Ontainer ID IMAGE COMMAND CREATED STATUS PORTS NAMES cf11bef3fc9d registry:2.3.0 "/bin/registry/etc/d" about a minute ago up about a minute 0. 0.0.0:5000->5000/TCP Registry

Next we need to use HTTP://192.168.12.132:5000/V2 to determine if the registry service starts properly, and if "{}" appears, it can indicate that the service is functioning properly.



Note: If you do a Docker pull registry operation first, the system will download a latest version of the image and then enable it with the same command: Docker run-d-v/root/registry:/var/lib/registry-p 5000:5000--restart=always--name Registry registry:latest, although the instance was started, the service was not functioning properly.


3, we can see, 132 local image has an Ubuntu image, we modify the relevant tag, so that his mark more obvious

root@controller:~# Docker tag ubuntu:14.04 192.168.12.132:5000/ubuntu:14.04 root@controller:~# Docker images                        REPOSITORY TAG IMAGE ID CREATED SIZE Swarm Latest a180b24e38ed 4 weeks ago 19.34 MB Docker/ucp-proxy 1.1.1 354  629dc8529 5 weeks ago 17.43 MB DOCKER/UCP-CFSSL 1.1.1 3b3684098101 5 weeks ago 53.61 MB DOCKER/UCP latest 40fe8a8c618e 5 weeks ago 20.49 MB do        Cker/ucp-auth 1.1.1 7b0a22fd86df 5 weeks ago 26.82 MB Docker/ucp-controller 1.1.1 C1ADA015CDB4 5 weeks ago 26.23 MB DOCKER/UCP-ETCD 1.1.1 C B7711A7FEA2 5 weeks ago 35.31 MB docker/ucp-compose 1.1.1 c6565efb4f69 5 Wee KS ago 58.61 MB Docker/ucp-auTh-store 1.1.1 4fbf8982055b 5 weeks ago 57.78 MB Docker/ucp-swarm 1.1.1         7A1BCEDACF02 5 weeks ago 19.34 MB Docker/ucp-dsinfo 1.1.1 782b4aca1228        7 weeks ago 68.51 MB 192.168.12.132:5000/ubuntu 14.04 b72889fa879c $ weeks ago                     188 MB ubuntu 14.04 b72889fa879c weeks ago 188 MB Registry              2.3.0 5eaced67751b 4 months ago 165.7 MB Registry Latest
 Bca04f698ba8 5 months ago 422.9 MB
We see that the Ubuntu image has been modified.


4. Push the Ubuntu image to the mirrored warehouse

root@controller:~# Docker push 192.168.12.132:5000/ubuntu:14.04 The
push refers to a repository [ 192.168.12.132:5000/ubuntu]
5f70bf18a086:pushed
f75f146a5022:pushed
711b0bd2cb6a:pushed
595d1d53a534:pushed
14.04:digest:sha256:f92c2bec713942c44219e8bd513c255543c9acda764ccabbe3f940eca696e97e size:1151

5, remember that we have attached the directory of the Mirror warehouse to the local/root/registry, we look at the relevant directory, look at the relevant image file.

root@controller:~# cd/root/
. cache/   registry/
root@controller:~# cd/root/registry/docker/registry/v2 /
blobs/        repositories/
root@controller:~# cd/root/registry/docker/registry/v2/repositories/
root@controller:~/registry/docker/registry/v2/repositories# ls
ubuntu

We see that the Ubuntu image file has been stored in this directory



6. Next, we just need to confirm that the other container server's/etc/default/docker file added registry trusted option, we can download the relevant image through the Docker pull command.

root@docker1:~# Docker images
REPOSITORY          TAG                 IMAGE ID            CREATED
swarm               Latest              A180b24e38ed        4 weeks ago
root@docker1:~# Docker pull 192.168.12.132:5000/ubuntu:14.04
14.04:pulling from Ubuntu

759d6771041e:pull Complete
8836b825667b:pull complete
c2f5e51744e6:pull
complete A3ed95caeb02:pull Complete
Digest:sha256:f92c2bec713942c44219e8bd513c255543c9acda764ccabbe3f940eca696e97e
status:downloaded Newer image for 192.168.12.132:5000/ubuntu:14.04
root@docker1:~# Docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED
swarm                        latest              a180b24e38ed        4 weeks ago
192.168.12.132:5000/ubuntu   14.04               b72889fa879c        Weeks AG

Of course, all are local connections, download speed naturally can be guaranteed.


As we can see in the image above, our image files can be stored locally or distributed storage software, we can store the image in Glusterfs,ceph, or OpenStack Swift.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.