I. Docker private warehouse

The last article explained how to use Dockerfile to build your own image on top of an existing image, so if you want to use an image on a team, you need a repository, and there are several ways to share private images.

1. Upload the image to Docker Hub

2. Use the third-party Docker Harbor

3. Create a private mirror repository

The first method requires you to register an account in Docker Hub and log in locally to upload your image, but this method is not secure because anyone can share your image. Is not recommended.

The second method requires downloading Docker Harbor installation, which is an enterprise-level Registry server for storing and distributing Docker images and requires Docker Compose support. There are also user-friendly interface operation, recommended this method.

The third is that Docker provides a Registry image called docker-Distribution. Let’s deploy this simple today.

Second, use Docker-distribution to build a private warehouse

1. Run the installation command

yum install docker-registry
Copy the code

2. Run the following command to check the installation

rpm -ql docker-distribution
Copy the code

The/etc/docker – distribution/registry/config. Yml: the configuration file

/var/lib/registry: local repository

/usr/bin/registry: main program

The/usr/lib/systemd/system/docker – distribution. Service: start the program

3. Start a private warehouse

systemctl start docker-distribution.service
Copy the code

By default, it listens on port 5000. Use SS-TNL to check port listening on Linux

4. Push the image to a private repository

(1) Use the docker tag command to re-label the image

Docker tag my_nginx: latest cnode 1:50 00 / nginx: v1.1Copy the code

Cnode-1:2000 is the address and IP address of the repository, and nGIxn is the top-level repository. If no tag is added, all images named nginx will be pushed.

(2) Push the image

Docker push cnode 1:50 00 / nginx: v1.1Copy the code

5. If push fails

Docker only supports HTTPS by default, but does not support HTTP. In this case, the private warehouse address needs to be marked as an insecure Registry in the docker configuration file /etc/dock/daemon. json

vim /etc/docker/daemon.json


{
  "registry-mirrors": ["https://kewfdyw2.mirror.aliyuncs.com"],
  "insecure-registries": ["cnode-1:5000"]
}
Copy the code

You need to restart the Docker after changing the configuration file.

Push again, the situation is as follows:

It indicates that the push is successful.

6. Check the warehouse

You need to go to /var/lig/registry to check, as shown below:

7. Pull images on other machines

The private repository needs to be added as non-secure in the docker configuration file /etc/dock/daemon. json.

For example, I need to pull the mirror in CNode-2

(1) Configure /etc/docker-daemon. json first. After the configuration, you need to restart it to take effect

{
  "registry-mirrors": ["https://kewfdyw2.mirror.aliyuncs.com"],
  "insecure-registries": ["cnode-1:5000"]
}
Copy the code

(2) Then run the command to pull the mirror

Docker pull cnode 1:50 00 / nginx: v1.1Copy the code

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

I’m Liusy, a programmer who likes to work out.

For more dry goods and the latest news, please follow the official account: Ancient False God

If it is helpful to you, a point of attention is my biggest support!!