05 | Warehouse visit

05 | Warehouse visit

How to better store and distribute images, Docker's mirror warehouse.
We can not only use public mirror warehouses to store and distribute images, but also build private mirror warehouses ourselves

What is a warehouse?

Repository is a place to store and distribute Docker images. Docker Hub is used to provide Docker image storage and distribution.

Registration server (Registry) and warehouse (Repository). The registration server is the actual server that stores the warehouse, and the warehouse can be understood as a specific project or directory; the registration server can contain many warehouses, and each warehouse can contain multiple mirrors . For example, my mirror address is docker.io/centos, docker.io is the registration server, and centos is the warehouse name. The relationship between them is shown in Figure 1.
Insert picture description here

Public mirror repository

Public mirror warehouses are generally provided by the Docker official or other third-party organizations (Ali Cloud, Tencent Cloud, NetEase Cloud, etc.), which allow everyone to register and use the mirror warehouse.

Docker Hub is the world's largest image market. There are currently more than 10w container images. These container images are mainly from software vendors, open source organizations and communities. Most of the operating system images and software images can be downloaded and used directly in Docker Hub.

We first visit the Docker Hub official website and click the register button to enter the account registration interface. After registration is complete, we can click Create Warehouse to create a new warehouse to push the mirror image
[External link image transfer failed, the source site may have anti-theft link mechanism, it is recommended to save the image and upload it directly (img-PIKe5b2F-1602229727946)(./ img/docker create mirror warehouse.png)]

Let's use an example to demonstrate how to push the mirror to your own warehouse.

First, we use the following command to pull the busybox image:

docker pull busybox 

Before pushing the mirror warehouse, we need to log in to the mirror server using the docker login command, because only logged in users can push the mirror to the warehouse.

$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: gavinhu04
Password:
Login Succeeded

The docker login command will request Docker Hub by default. If you want to log in to a third-party mirror warehouse or a self-built mirror warehouse, you can add a registered server after docker login. For example, if we want to log in to the Alibaba Cloud image server, use docker login registry.cn-beijing.aliyuncs.com and enter the username and password of the Alibaba Cloud image service.

Before pushing the local image to the custom warehouse, we need to "rename" the image. Note that you must use your own docker username (gavinhu04) to correctly push it to the mirror warehouse you created. Use the docker tag command to transfer the image "Rename":

docker tag busybox gavinhu04/busybox

After the image is "renamed", use the docker push command to push the image to the warehouse created by yourself.

docker push gavinhu04/busybox

Build a private warehouse

Start local warehouse

Docker officially provides an open source image warehouse Distribution , and the image is stored in the Registry of Docker Hub for us to download.

We can start a local mirror warehouse with the following command:

$ docker run -d -p 5000:5000 --name registry registry:2.7

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
d7e449a8a93e        registry:2.7        "/entrypoint.sh /etc…"   50 seconds ago      Up 49 seconds       0.0.0.0:5000->5000/tcp   registry

At this point, we have a private mirror warehouse with an access address of localhost and a port number of 5000.

Push the image to the local warehouse

We still use busybox mirroring as an example. First, we use the docker tag command to "rename" the busybox image to localhost:5000/busybox

$ docker tag busybox localhost:5000/busybox

At this point, Docker created an alias localhost:5000/busybox for the busybox image, with localhost:5000 as the host name and port, and Docker will push the image to this address.

Use docker push to push the image to the local warehouse:

$ docker push localhost:5000/busybox
The push refers to repository [localhost:5000/busybox]
514c3a3e64d4: Layer already exists
latest: digest: sha256:400ee2ed939df769d4681023810d2e4fb9479b8401d97003c710d0e20f7c49c6 size: 527

At this point, we verify that the image is pulled from the local mirror repository.

$ docker pull localhost:5000/busybox
Using default tag: latest
latest: Pulling from busybox
Digest: sha256:400ee2ed939df769d4681023810d2e4fb9479b8401d97003c710d0e20f7c49c6
Status: Downloaded newer image for localhost:5000/busybox:latest
localhost:5000/busybox:latest

Use the docker image ls busybox command to view the local busybox image:

$ docker image ls busybox

Persistent image storage

We know that containers are stateless. The startup method of the above private warehouse may cause the loss of the image, because we did not persist the data information of the warehouse to the host disk, which is unacceptable in the production environment. Below we use the following command to persist the image to the host directory:

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

In fact, the persistent storage of the registry supports many types in addition to the local file system, such as S3, Google Cloud Platform, Microsoft Azure Blob Storage Service and other storage types.

At this point, although our mirror repository can be accessed and pulled locally, if you are on another machine, you cannot access the mirror repository through Docker, because Docker requires that the mirror repository accessed by non-localhost must use HTTPS. Need to build an externally accessible mirror warehouse.

Build an externally accessible mirror warehouse

Stay more

to sum up

  1. The relationship between registration server, warehouse and mirror
  2. Create a public mirror warehouse and push local mirrors to the public warehouse.
  3. Build a local warehouse

Problems encountered

Cause Analysis:

How to switch desktop shortcuts in win10:
win + ctrl + left/right

List running containers
docker ps

Show all containers, including
docker ps -a that is not running

Guess you like

Origin blog.csdn.net/Cirtus/article/details/108980104
05