搭建私有云仓库
首先登录后直接在页面搜索栏中搜索“容器镜像服务”
进入后直接选择个人版(可以免费使用)
选择镜像仓库后创建一个镜像仓库
在创建仓库之前我们先创建一个命名空间
然后可以再创建我们的仓库,可以与我们的github账号进行关联
创建完后可以点击到我们的库内可以看到有帮助文档,接下来就我们就可以自己将我们虚拟机上的镜像拉到自己的私有云仓库
首先登录我们的云仓库账号
[root@master ~]# sudo docker login --username=NANNANMM registry.cn-hangzhou.aliyuncs.com
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-storeLogin Succeeded
#这里的WARNING是提醒我们的密码以明文的形式在/root/.docker/config.json中存储#这是我们的退出方法
[root@master ~]# docker logout
Removing login credentials for https://index.docker.io/v1/#查看镜像
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest e4720093a3c1 2 weeks ago 187MB
busybox latest 3f57d9401f8d 6 weeks ago 4.26MB
ubuntu 18.04 f9a80a55f492 9 months ago 63.2MB
centos 7 eeb6ee3f44bd 2 years ago 204MB#将虚拟机内的镜像打好表桥准备上传到我们的云镜像仓库
sudo docker tag 镜像ID registry.cn-hangzhou.aliyuncs.com/命名空间/镜像仓库名称:镜像版本号
[root@master ~]# docker tag eeb6ee3f44bd registry.cn-hangzhou.aliyuncs.com/redh/test:7#从这里看一看到我们拉取的镜像已经成功打标签
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest e4720093a3c1 2 weeks ago 187MB
busybox latest 3f57d9401f8d 6 weeks ago 4.26MB
ubuntu 18.04 f9a80a55f492 9 months ago 63.2MB
centos 7 eeb6ee3f44bd 2 years ago 204MB
registry.cn-hangzhou.aliyuncs.com/redh/test 7 eeb6ee3f44bd 2 years ago 204MB#然后将我们打好标签的镜像上传到我们的云镜像仓库
[root@master ~]# docker push registry.cn-hangzhou.aliyuncs.com/redh/test:7
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/redh/test]
174f56854903: Pushed
7: digest: sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f size: 529
这时我们就可以尝试将本地的镜像以及我们打标签的镜像删除,拉取我们上传的云镜像
[root@master ~]# docker rmi centos:7
Untagged: centos:7
Untagged: centos@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
[root@master ~]# docker rmi registry.cn-hangzhou.aliyuncs.com/redh/test:7
Untagged: registry.cn-hangzhou.aliyuncs.com/redh/test:7
Untagged: registry.cn-hangzhou.aliyuncs.com/redh/test@sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest e4720093a3c1 2 weeks ago 187MB
busybox latest 3f57d9401f8d 6 weeks ago 4.26MB
ubuntu 18.04 f9a80a55f492 9 months ago 63.2MB#可以看到我们没有了7的镜像,现在就从云上获取一个
docker pull registry.cn-hangzhou.aliyuncs.com/命名空间/镜像仓库名称:镜像版本号
[root@master ~]# docker pull registry.cn-hangzhou.aliyuncs.com/redh/test:7
7: Pulling from redh/test
Digest: sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/redh/test:7
registry.cn-hangzhou.aliyuncs.com/redh/test:7
现在就有了从云获取的7镜像,不过这个名字过于繁琐我们还需要给此镜像改名
#docker tag registry.cn-hangzhou.aliyuncs.com/命名空间/库名:版本号 更换的镜像名
[root@master ~]# docker tag registry.cn-hangzhou.aliyuncs.com/redh/test:7 mycentos
这时就可以查看到有一个新的名为mycentos的镜像,我们就可以删除复杂命名的相同镜像
[root@master ~]# docker rmi registry.cn-hangzhou.aliyuncs.com/redh/test:7
Untagged: registry.cn-hangzhou.aliyuncs.com/redh/test:7
Untagged: registry.cn-hangzhou.aliyuncs.com/redh/test@sha256:dead07b4d8ed7e29e98de0f4504d87e8880d4347859d839686a31da35a3b532f
到这里就完成了我们搭建云镜像仓库的作用。