Set up the Alibaba Cloud private Docke mirror warehouse in minutes

Foreword:

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

Build a private mirror warehouse:

1. Log in to Alibaba Cloud and select "Container Image Service"
Insert picture description here
2. Create Container Image Service

The first time you enter the container mirroring service, you will be prompted to activate the service and set the registry login password. Remember this password, and you will use it later.
Insert picture description here
3. Create a namespace

You must create a namespace before creating a mirror warehouse. Note that an account can only create up to 3 namespaces, and they cannot be modified after setting.
Insert picture description here
4. Create a mirror warehouse

Select the namespace created before, then select the warehouse type, and fill in the corresponding information to create a mirror warehouse.
Insert picture description here
5. View the information of the private mirror warehouse.
Insert picture description here
Insert picture description here
 In the mirror warehouse, you can see the public network address and the private address of the private mirror warehouse. There is also a detailed operation guide provided by Alibaba Cloud below. Including the warehouse permissions that can be set for some sub-accounts.

6. Log in to the Alibaba Cloud Mirror Warehouse

[root@localhost ~]# sudo docker login --username=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

After the login is successful, there is a warning message at the bottom, which means that our password is recorded in the /root/.docker/config.json file in plain text. After that, no password is required to log in. If you want to delete the password, you can go to /root/ Delete from the .docker/config.json file.
Insert picture description here
7. Upload the image to the Alibaba Cloud private image warehouse

  • 7.1 Select a mirror warehouse for the image to be uploaded and label it with the version number (if the mirror warehouse selected when labeling was not previously created on Alibaba Cloud, the mirror warehouse will be automatically created when uploading the image)

sudo docker tag mirror ID registry.cn-zhangjiakou.aliyuncs.com/namespace/mirror warehouse name: mirror version number

[root@localhost ~]# docker images         
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
mytomcat               v1                  c0b9a81cd686        5 days ago          639MB

[root@localhost ~]# docker tag c0b9a81cd686 registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0             
 //给镜像ID为c0b9a81cd686的镜像打上版本标签,选择上传的镜像仓库名称为mytomcat,版本为1.0

[root@localhost ~]# docker images
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
mytomcat                                                          v1                  c0b9a81cd686        5 days ago          639MB
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   1.0                 c0b9a81cd686        5 days ago          639MB
  • 7.2 Upload the image with the version number label to the
     Alibaba Cloud private image warehouse sudo docker push registry.cn-zhangjiakou.aliyuncs.com/namespace/image warehouse name: image version number
[root@localhost ~]# docker push registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0      
 //上传版本号为1.0的镜像至镜像仓库名为mytomcat的镜像仓库中
The push refers to repository [registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat]
377b5223baf6: Layer already exists
5f5f84b30131: Layer already exists
2a0b10f7f9ba: Layer already exists
2653d992f4ef: Layer already exists
1.0: digest: sha256:083382b6cc0b5d039c91e99f791bac10dd68e794f776b93e046ae0a14d0e0a16 size: 1166
  • 7.3 Upload another mirror with the mirror version number of 2.0 to the mytomcat mirror warehouse
[root@localhost ~]# docker images
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
mytomcat                                                          v1                  c0b9a81cd686        5 days ago          639MB
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   1.0                 c0b9a81cd686        5 days ago          639MB
mycentos                                                          2.0                 040f98e77919        6 days ago          291MB

[root@localhost ~]# sudo docker tag 040f98e77919 registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:2.0
  //将镜像ID为040f98e77919的镜像上传至mytomcat镜像仓库中,版本号为2.0

[root@localhost ~]# sudo docker push registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:2.0
The push refers to repository [registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat]
b49a94a64103: Pushed
88d59513ebbc: Pushed
2653d992f4ef: Layer already exists
2.0: digest: sha256:88025ccfcc439853ecab8f4b5ca7a2f44ca09f180bfc0e8dab983083e9f53ca1 size: 953

8. View the uploaded image

It can be seen that when uploading a mirror, we can choose which mirror warehouse to upload the currently uploaded mirror to. A mirror warehouse can store multiple images of different versions.
Insert picture description here
Insert picture description here
Insert picture description here
 You can see that the mirrors of version 1.0 and 2.0 have been uploaded in the current mytomcat mirror warehouse.

9. Pull the image from the Alibaba Cloud image warehouse

9.1 Because there is only the previously uploaded image in the Alibaba Cloud Mirror Warehouse, first delete the local mirror, and then pull it from the Alibaba Cloud Mirror Warehouse to the local.

[root@localhost ~]# docker rmi registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0
  //删除标签为版本1.0,镜像仓库为mytomcat的镜像
Untagged: registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0
Untagged: registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat@sha256:083382b6cc0b5d039c91e99f791bac10dd68e794f776b93e046ae0a14d0e0a16

[root@localhost ~]# docker images
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
mytomcat                                                          v1                  c0b9a81cd686        5 days ago          639MB
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   2.0                 040f98e77919        6 days ago          291MB
mycentos                                                          2.0                 040f98e77919        6 days ago          291MB
  • 9.2 Pull the mirror image from the
    Alibaba Cloud mirror warehouse sudo docker pull registry.cn-zhangjiakou.aliyuncs.com/namespace/mirror warehouse name: mirror version number
[root@localhost ~]# sudo docker pull registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0
 //从阿里云镜像仓库mytomcat中拉取版本为1.0的镜像
1.0: Pulling from lss-docker-images/mytomcat
Digest: sha256:083382b6cc0b5d039c91e99f791bac10dd68e794f776b93e046ae0a14d0e0a16
Status: Downloaded newer image for registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0

[root@localhost ~]# docker images
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   1.0                 c0b9a81cd686        5 days ago          639MB
mytomcat                                                          v1                  c0b9a81cd686        5 days ago          639MB
mycentos                                                          2.0                 040f98e77919        6 days ago          291MB
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   2.0                 040f98e77919        6 days ago          291MB

10. Mirror rename

Everyone knows that the tags that we used to upload images were very long, and when they were later pulled from the Alibaba Cloud mirror warehouse, the names would be extremely long and inconvenient to operate, so we renamed them.

[root@localhost ~]# docker images
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
mytomcat                                                          v1                  c0b9a81cd686        5 days ago          639MB
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   1.0                 c0b9a81cd686        5 days ago          639MB
mycentos                                                          2.0                 040f98e77919        6 days ago          291MB
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   2.0    

We renamed the namespace that we just pulled to lss-docker-images, the mirror repository named mytomcat, and the mirror registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat 1.0 with the version number of 1.0.

[root@localhost ~]# docker tag registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0 mytomcat:1.0
 //将上面的镜像重命名为mytomcat:1.0

[root@localhost ~]# docker rmi registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat:1.0

After renaming a mirror with a long name, remember to delete the mirror with a long name, because we have already renamed one, and the mirror will remain locally if it is not deleted.

[root@localhost ~]# docker images
REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
mytomcat                                                          1.0                 c0b9a81cd686        5 days ago          639MB
mytomcat                                                          v1                  c0b9a81cd686        5 days ago          639MB
mycentos                                                          2.0                 040f98e77919        6 days ago          291MB
registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat   2.0                 040f98e77919        6 days ago          291MB

Reference link:

https://mp.weixin.qq.com/s/gAzKK_CPGIJQLkM5U6OMNA

Guess you like

Origin blog.csdn.net/qq_40907977/article/details/114688646
Recommended