(Solved) Create a local mirror warehouse in the docker/docker desktop for window environment

Problem phenomenon:

Recently, I am studying how to create a docker local mirror warehouse in the window server environment . Since the Internet is almost all based on the Linux server environment, this goal can be achieved through reference, learning and practice.


problem analysis:

Through self-study, I discovered some basic logical principles for creating a docker mirror warehouse, which is definitely the same no matter in the window or linux environment.

Note: The directly downloaded image in docker is stored in the local docker library , not the local private image warehouse !

 

the difference:

Local docker library: It is the library that comes with the docker service after docker is installed .

The machine Private mirroring warehouse: in the docker services in , start registry container, to create the one for storing image library , since the container can and the local port binding, it is also called the machine a mirror private warehouse .

 

Configuration :

window, docker/docker desktop (docker desktop is recommended for window environment )

 

Steps :

1. Start docker desktop, open the cmd command window, enter:

docker search registry

 

2. See the registry mirror, enter:

docker pull registry

 

3. Check the mirror and see the registry mirror that has been downloaded to the local

docker images    #查看本地镜像,可以看到registry镜像

 

4. Check the image and see the registry image that has been downloaded to the local. The next step is to deploy the registry service container.

First create a folder on the machine (for example: create a registry folder under the E drive , and set it to share )

enter:

docker run -d -p 5000:5000 --restart=always -v E:/registry:/var/lib/registry registry:latest

Set self-restart, bind the local 5000 port, and map the path of the image storage location in the container to the local path.

 

5. View the container, see the registry container that has been deployed , enter:

docker ps    #查看运行中的容器

 

6. After the container is deployed, the local mirror warehouse is built. The next step is to add the warehouse address to connect.

Can be implemented directly visualized docker desktop configuration, simple: warehouse address of the image ( the unit IP: 5000 ) was added to I nsecure-Registries in :

 

7. Restart docker desktop, create a new image by renaming (docker tag image id, image new tag name), pay attention to the format, it must start with (local ip:5000/)

 

8. Upload the mirror image to the local mirror warehouse, enter:

docker push 

Since I uploaded it once in advance, it shows Layer already exists (data already exists)

You can see latest: digest: sha256:,,, size:. . . (That is, the push is successful)

The following shows an example of the result graph of uploading the mirror first:

 

9. Check the mirror in the local mirror warehouse address to verify whether the mirror is uploaded successfully:

Method 1: Open the browser and enter the local ip:5000/v2/_catalog   to access the docker interface and view the mirror information ( this method is the most accurate ):

Method 2: Open the E:\registry\docker\registry\v2\repositories file path of the machine directly , because all the mirrors will be stored in this directory, you can see that there is a registry folder inside, this folder is the mirror pushed just now data files:

Note: It is recommended that novices do not use the registry mirror to test, because the name of this mirror is easily confused with the registry in the path. The concept is different and needs to be distinguished.

Enter the file and you can see the following information, which means that the push is successful :

10. Delete the mirror in the local mirror warehouse. At first I thought of the method of deleting directly in the local folder, but there are disadvantages:

Open the E:\registry\docker\registry\v2\repositories file path of the machine  and delete the registry folder ;

Similarly, open the  E:\registry\docker\registry\v2\blobs  file path and delete the sha256 folder :

Use method 1 to verify:

It seems that the deletion was successful, but the fact is not, because when we push again, we will find that the local private mirror library already exists, which shows that the deletion was not successful:

So I thought that the most direct way is to go to the container and check the specific storage location of the mirror image. Whether there is still a mirror or not, I found something magical:

When I explored the /var/lib/registry/docker/registry/v2/repositories path in the  registry container step by step  through the  ls command and the cd command , I found that the image deleted using the above method still exists here intact ; That is to say delete invalid;

So I went to look at the configuration file of the registry container :

I can’t see why, but by looking up the information on the Internet, I know: this is because

     The delete function of the registry container is disabled by default .

I think the prohibition of deleting the function should be for security reasons.

However, driven by curiosity, I went to check the information and found that there is a way to modify the configuration file on the Internet, and the delete function can be activated, as follows:

I won’t practice it here, and there is another safer method available online:

       Just go to the /var/lib/registry/docker/registry/v2/repositories path in the  registry container and directly delete the image you want to delete:

Or more simply

1. Execute the following commands directly in cmd:

docker exec <容器名> rm -rf /var/lib/registry/docker/registry/v2/repositories/<镜像名>

Checking through the ls command  , it is found that the folder is empty, that is, the deletion is successful, and the exit command can be executed to exit the container : (Question: Do you need to delete the files under the blobs? Guess that the blobs may be temporary data)

2. Then you need to perform garbage collection operations:

docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml

Result feedback:

Seeing the 3 0s in this feedback, I always feel that the deletion may not be successful this time.

Then I pushed again and found that it still exists, but after many practices, I found that occasionally it was successful:

So I guess, because this garbage collection operation is generally not executed immediately, it may take some time to ensure that the cached data is actually cleared. This garbage collection mechanism may be related to the blobs folder.

verification:

So after deleting the mirror file, I waited for 10 minutes before performing this garbage collection operation, and found that there was new feedback:

I feel hopeful, but when I push again, it still says it already exists:

After trying all kinds of things, I suddenly thought of the legendary method that can solve 99% of the problems: restart.

So after executing the garbage collection operation command, I executed the restart command, and then pushed after restarting. I found that it was OK. After many attempts, I could delete it successfully. So far I finally solved the problem of deleting the mirror:

to sum up:

1. Don't delete the mirror if it's okay, it's too much trouble.

2. The deletion steps are:

   10.2.1: Open the E:\registry\docker\registry\v2\repositories file path of the machine and  delete the image file you want to delete.

   10.2.2: In cmd, execute garbage collection operation command:

docker exec b0533d3f7f8e bin/registry garbage-collect /etc/docker/registry/config.yml

   10.2.3: Restart the registry container

docker restart registry容器的id

   10.2.4: Push again to upload the local docker library image

docker push 192.168.2.120:5000/minio

11. Access to the mirror warehouse address between servers:

Such as: A server (local machine) address: 192.168.2.120:5000

       Server B address: 192.168.2.220:5000

To access the  mirror warehouse address of  B in A , pull the mirror from the warehouse of B:

11.1 First , add (B) the mirror warehouse address in the docker configuration of this machine ( A) :

11.2 then start / restart the machine (A) of the docker desktop.

11.3 Create a mirror warehouse of B on the B server in advance , and create a mirror starting with B's ip:5000/ , and push it to the mirror warehouse address of b:

11.4 Open the browser in this machine (A) to view the information in the mirror library of B, you can see that there is only one minio mirror that has just been pushed in the B library, and the access is successful:

11.5 Pull the B library mirror image from this machine (A), and enter:

docker pull 

downloading:

Download completed:

Note: This is the docker warehouse downloaded to the local machine (A). If you need to store it in the local private mirror warehouse, you need to create a new mirror and push it in the same way as above, as follows:

 

 

Guess you like

Origin blog.csdn.net/weixin_42585386/article/details/113498406