ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

分分钟搞定阿里云私有Docke镜像仓库的搭建

2021-06-11 16:55:17  阅读:237  来源: 互联网

标签:搞定 aliyuncs mytomcat images 镜像 docker com Docke


前言:

 所谓私有仓库,也就是在本地(局域网)搭建的一个类似公共仓库的东西,搭建好之后,我们可以将自己的镜像提交到私有仓库中。这样我们既能使用 Docker 来运行我们的项目镜像,也避免了商业项目暴露出去的风险。

搭建私有镜像仓库:

1.登录阿里云选择“容器镜像服务”
在这里插入图片描述
2.创建容器镜像服务

 第一次进入容器镜像服务会提示开通服务并设置Registry登录密码,记住这个密码,后面都会用到。
在这里插入图片描述
3.创建命名空间

 创建镜像仓库之前必须先创建命名空间,注意一个账号最多只可以创建3个命名空间,并且设置后不可以修改。
在这里插入图片描述
4.创建镜像仓库

 选择之前创建好的命名空间,然后选择仓库类型,填上相应的信息创建镜像仓库。
在这里插入图片描述

5.查看私有镜像仓库信息
在这里插入图片描述
在这里插入图片描述
 在镜像仓库中可以看到该私有镜像仓库的公网地址跟专有地址,底下也有阿里云提供的详细操作指南。包括可以设置一些子账号的仓库权限。

6.登录阿里云镜像仓库

[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

 登录成功后底下是一个警告信息,意思是我们的密码以明文格式记录在/root/.docker/config.json文件中,之后再登录就不需要密码了,如果要删除密码就可以去/root/.docker/config.json文件中删除。
在这里插入图片描述
7.上传镜像至阿里云私有镜像仓库

  • 7.1 为要上传的镜像选择镜像仓库并打上版本号标签(打标签时选择的镜像仓库如果先前没有在阿里云上创建,那么在上传镜像的时候会自动创建镜像仓库)
    sudo docker tag 镜像ID registry.cn-zhangjiakou.aliyuncs.com/命名空间/镜像仓库名称:镜像版本号
[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 将打好版本号标签的镜像上传至阿里云私有镜像仓库中
    sudo docker push registry.cn-zhangjiakou.aliyuncs.com/命名空间/镜像仓库名称:镜像版本号
[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 再上传一个镜像版本号为2.0的镜像到mytomcat镜像仓库中
[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.查看上传的镜像

 可以看到我们在上传镜像的时候可以选择将当前要上传的镜像上传至哪一个镜像仓库中,一个镜像仓库可以存放多个不同版本的镜像。
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
 可以看到目前mytomcat镜像仓库中已经上传了版本分别为1.0跟2.0的镜像。

9.从阿里云镜像仓库拉取镜像

  • 9.1 因为阿里云镜像仓库中只有之前上传的镜像,所以现在先将本地的这个镜像删除,再从阿里云镜像仓库拉取到本地。
[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 从阿里云镜像仓库拉取镜像
    sudo docker pull registry.cn-zhangjiakou.aliyuncs.com/命名空间/镜像仓库名称:镜像版本号
[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.镜像重命名

 大家都知道我们在之前上传镜像的时候打的标签都很长,后续从阿里云镜像仓库拉取下来的时候,名字会特别长,不方便操作,所以我们将他们重命名。

[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                 040f98e77919        6 days ago          291MB

 我们将刚才拉取的命名空间为lss-docker-images,镜像仓库名为mytomcat,版本号为1.0的镜像registry.cn-zhangjiakou.aliyuncs.com/lss-docker-images/mytomcat 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
 //重命名后删除之前的镜像

 将某个名字很长的镜像重命名后,记得将该名字很长的镜像删除,因为我们已经重新命名了一个了,这个镜像不删除也会一直在本地。

[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

 

标签:搞定,aliyuncs,mytomcat,images,镜像,docker,com,Docke
来源: https://blog.51cto.com/u_15266039/2896872

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有