Get the App
SLTechnology News&Howtos  ›  Servers  › 

Docker Learning-Building a Local Registry

Shulou Source: shulou.com Published: 2022-06-02 14:10:39 10月15日 Update

The most direct way to save and distribute images is to use Docker H u b, a public Regsitry maintained by Docker, where users can save their images to Docker H u b's free repository. If you do not want others to access your own image, you can also buy private repository.

Generally speaking, we can upload and download images using Docker H u b. Although it is very convenient, there are still some restrictions, such as:

1. Requires an external network connection, and the upload and download speed is slow.

2. The image uploaded to Docker H u b can be accessed by anyone. Although you can use private repositroy, it is not free.

3. For security reasons, many organizations do not allow images to be placed on the public network.

The solution is a local Registry in a single room.

Docker has made Registry open source, and there is also an official mirror Registry on Docker H u b.

We can run our own Registry in Docker

Using dockerfile to build httpd

Before using the repository, let's first build a httpd image and save it locally

First create the dockerfile directory and create the dokcerfile file

Cd ~ mkdir dokcerfile cd dockerfiletouch dockerfie

Edit the dockerfile as follows

Then build the http image

Docker build-t httpd:v11-f dockerfile / root/dockerfile

As shown below, the build is successful

Check the mirror image

Docker images

Start the registry container

First create the / myregistry directory under the root directory to store the mirrored data

The image used this time is registry:2

Cd / mkdir / myregistry

Create a registry container using the following command

Docker run-d-p 5000UR 5000-v / myregistry:/var/lib/registry registry:2

Description:

1.-d launch the container in the background

2.-p maps port 5000 of the container to port 5000 of Host. 5000 is the registry service port

3.-v map the container's / var/lib/regsitry directory to Host's / myregistry, which is used to store mirrored data

Rename the mirror through docker tag to match the registry, as follows:

Docker tag yangchao/httpd:v1 127.0.0.1:5000/yangchao/httpd:v1

Change httpd:v11 to the format required by Registry, in the following format:

Only images on Docker Hub can omit registry-host: [port]

Rename the mirror to match the registry through docker tag as follows

Docker tag httpd:v11 127.0.0.1:5000/yangchao/httpd:v11

Use the dokcer image command to check the mirror

Then upload yangchao/httpd:v11 to Registry

Docker push 127.0.0.1:5000/yangchao/httpd:v11

Then view the mirror in Registry

Curl 127.0.0.1:5000/v2/_catalog

You can view the corresponding image in the / myregistry directory

At this point, the local registry is created

Tags: Image container directory port command data method format check security success warehouse company single room reason only at the same time background official that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Shulou Technology Xiaomi Docker