Use Docker Registry to quickly build a private image repository

Source: Internet
Author: User
Tags docker registry

Use Docker Registry to quickly build a private image repository
1. Background

In Docker, when we run docker pull xxx, we may be curious. Where will Docker find and download the image?

It is actually searched from the address registry.hub.docker.com. This is the public repository provided by Docker for us. You can see and use the image above. Therefore, we can also pull the image with the repository address, such as docker pull.

If we want to use Docker in the company, it is basically impossible for us to upload commercial projects to a public warehouse. What if we want to share multiple machines?

Because of this need, private warehouses are useful.

The so-called private warehouse is something similar to a public warehouse built locally (LAN). After the building, we can submit the image to the private warehouse. In this way, we can use Docker to run our project images and avoid the risks exposed by commercial projects.

Below we use the officially provided registry image to build a private image repository. Of course there are many other methods.

2. Environment

Prepare two servers with docker installed:
Server machine (with the registry host name): A private docker repository server that runs the registry container;
Test-side machine (host name: node): A common docker server. Download a test image busybox from this server and upload it to the registry server for testing;

3. Deployment (server operations)

3.1 download the image registry

[Root @ registry ~] # Docker pull registry
Using default tag: latest
Latest: Pulling from library/registry
81033e7c1d6a: Pull complete
B235084c2315: Pull complete
C692f3a6894b: Pull complete
Ba2177f3a70e: Pull complete
A8d793620947: Pull complete
Digest: sha256: sha256
Status: Downloaded newer image for registry: latest

3.2 check whether pull is down.

3.3 run the registry container

[Root @ registry ~] # Docker run-itd-v/data/registry:/var/lib/registry-p 5000: 5000 -- restart = always -- name registry: latest
Bytes

Parameter description
-Itd: open a Pseudo Terminal in the container for interactive operations and run it in the background;
-V: bind the/data/registry directory of the host to the/var/lib/registry directory of the container (this directory is the directory for storing image files in the registry container ), to realize data persistence;
-P: ing port. Access port 5000 of the host machine to access the service of the registry container;
-- Restart = always: This is the restart policy. If the container exits abnormally, the container is automatically restarted;
-- Name registry: Create a container named registry. you can name it as needed;
Registry: latest: This is the pull image;

3.4 test all images in the image repository

[Root @ registry ~] # Curl http: // 127.0.0.1: 5000/v2/_ catalog
{"Repositories": []}

It is empty because it is just running and there is no image content in it.

4. Test the image repository (test-side operations)

4.1 modify the image source and restart the docker Service

[Root @ node ~] # Vim/etc/docker/daemon. json
{
"Registry-mirrors": ["https://registry.docker-cn.com"]
}

[Root @ node ~] # Systemctl restart docker

4.1 download the busybox Image

[Root @ node ~] # Docker pull busybox
[Root @ node ~] # Docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Busybox latest f6e427c148a7 36 hours ago 1.15 MB

4.2 tag an image

[Root @ node ~] # Docker tag busybox: latest 172.18.18.90: 5000/busybox: v1

Format description: Usage: docker tag SOURCE_IMAGE [: TAG] TARGET_IMAGE [: TAG]

Busybox: lastest: this is the source image, which is also the image file from pull just now;
172.18.18.90: 500/busybox: v1: This is the destination image and the IP address and port of the registry private backup server;

Check the tag:

4.3 upload to backup storage

[Root @ node ~] # Docker push 172.18.18.90: 5000/busybox: v1
The push refers to repository [172.18.18.90: 5000/busybox]
Get https: // 172.18.18.90: 5000/v2/: http: server gave HTTP response to HTTPS client

Note that this is an error. You must use https to upload the file. You can modify daemon. json to solve the problem:

[Root @ node ~] # Vim/etc/docker/daemon. json
{
"Registry-mirrors": ["https://registry.docker-cn.com"],
& Quot; insecure-registries & quot;: [& quot; 172.18.18.90: 5000 & quot;]
}

Add the address of the private backup storage. Note that the writing format is json and there are strict writing requirements. Then restart the docker service:

[Root @ node ~] # Systemctl restart docker

You can see that there is no problem during the next upload:

[Root @ node ~] # Docker push 172.18.18.90: 5000/busybox: v1
The push refers to repository [172.18.18.90: 5000/busybox]
C5183829c43c: Pushed
V1: digest: sha256: c7b0a24019b0e6eda714ec0fa137ad42bc44a754d9cea17d14fba3a80ccc1ee4 size: 527

4.4 Test and download the image
The upload test is okay. Next we will test how to download the uploaded busybox image from the registry server and delete the image on the node host first:

[Root @ node ~] # Docker rmi-f $ (docker images-aq)
Untagged: 172.18.18.90: 5000/busybox: v1
Untagged: 172.18.18.90: 5000/busybox @ sha256: c7b0a24019b0e6eda714ec0fa137ad42bc44a754d9cea17d14fba3a80ccc1ee4
Untagged: busybox: latest
Untagged: busybox @ sha256: 2107a35b58593c58ec5f4e8f2c4a70d195321078aebfadfbfb223a2ff4a4ed21
Deleted: sha256: sha256
Deleted: sha256: c5183829c43c4698634093dc38f9bee26d1b931deba71dbee984f42fe1270d

Check that all images on the node host have been deleted:

[Root @ node ~] # Docker images
REPOSITORY TAG IMAGE ID CREATED SIZE

Then, download the busybox image from the registry server:

[Root @ node ~] # Docker pull 172.18.18.90: 5000/busybox: v1
V1: Pulling from busybox
D070b8ef96fc: Pull complete
Digest: sha256: c7b0a24019b0e6eda714ec0fa137ad42bc44a754d9cea17d14fba3a80ccc1ee4
Status: Downloaded newer image for 172.18.18.90: 5000/busybox: v1
[Root @ node ~] # Docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
172.18.18.90: 5000/busybox v1 f6e427c148a7 36 hours ago 1.15 MB

List all images:

[Root @ node ~] # Curl http: // 172.18.18.90: 5000/v2/_ catalog
{"Repositories": ["busybox"]}

List the tags of A busybox image:

[Root @ node ~] # Curl http: // 172.18.18.90: 5000/v2/busybox/tags/list
{"Name": "busybox", "tags": ["v1"]}

For more Docker tutorials, see the following:

Docker installation application (CentOS 6.5_x64) https://www.bkjia.com/Linux/2014-07/104595.htm
Configuration on Ubuntu 16.04 server using Docker https://www.bkjia.com/Linux/2017-06/145176.htm
Install Docker https://www.bkjia.com/Linux/2015-07/120444.htm in Ubuntu 15.04
Docker installation instance https://www.bkjia.com/Linux/2017-04/142666.htm
Docker create basic image https://www.bkjia.com/Linux/2017-05/144112.htm
How to install Docker and basic usage https://www.bkjia.com/Linux/2015-09/122885.htm on Ubuntu 15.04
Docker Use note https://www.bkjia.com/Linux/2016-12/138490.htm on Ubuntu 16.04
Use Docker to start https://www.bkjia.com/Linux/2017-04/142649.htm of frequently used applications in minutes
Ubuntu 16.04 Docker modify configuration file does not take effect solution https://www.bkjia.com/Linux/2017-05/143862.htm

Docker details: click here
Docker: click here

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151308.htm

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.