文章目录
- 1、准备镜像
- 2、创建命名空间
- 3、创建镜像仓库
- 4、推送镜像
1、准备镜像
[root@localhost ~]# docker pull centos
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 300e315adb2f 4 months ago 209MB
[root@localhost ~]# docker run -it centos
[root@70373a4e86f2 /]#
[root@70373a4e86f2 /]# [root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70373a4e86f2 centos "/bin/bash" 12 seconds ago Up 11 seconds eager_knuth
[root@localhost ~]# docker commit -a zuoxuchen -m "zuoxuchen_test_docker_centos_last" 70373a4e86f2 zuoxuchen_centos:1.4
sha256:57c8e3e58d02dbb14e3722a95ce24176d9dc85b713a7f413d6a2d4cb33ef0650
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zuoxuchen_centos 1.4 57c8e3e58d02 5 seconds ago 209MB
centos latest 300e315adb2f 4 months ago 209MB
2、创建命名空间
打开阿里云官网,搜索【容器镜像服务】;
打开网页【仓库管理】-【命名空间】-【创建命名空间】,由于我是使用过,所以提前创建好了两个命名空间,新用户是需要自己创建的;
创建一个新的命名空间,并赋予其名称,每一个账户可以拥有三个命名空间(一个公有,一个私有就足够我们使用了);
创建完成后可以修改仓库类型为公有还是私有,此处需要使用公有类型;
3、创建镜像仓库
打开【仓库管理】-【镜像仓库】-【创建镜像仓库】
配置新创建的镜像仓库,命令空间可以进行选择为公开还是私有,地域默认为
4、推送镜像
点击创建好的镜像仓库中的【管理】;
使用第三节的内容进行镜像推送,内容如下;
$ sudo docker login --username=左旭晨 registry.cn-hangzhou.aliyuncs.com
$ sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/zuoxuchen/docker_test:[镜像版本号]
$ sudo docker push registry.cn-hangzhou.aliyuncs.com/zuoxuchen/docker_test:[镜像版本号]
此处为root用户权限,不需要sudo提权命令,下述全部省略;
[root@localhost ~]# docker login --username=左旭晨 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-store
Login Succeeded
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zuoxuchen_centos 1.4 57c8e3e58d02 5 minutes ago 209MB
centos latest 300e315adb2f 4 months ago 209MB
[root@localhost ~]# docker tag 57c8e3e58d02 registry.cn-hangzhou.aliyuncs.com/zuoxuchen/docker_test:1.4.1
[root@localhost ~]# docker push registry.cn-hangzhou.aliyuncs.com/zuoxuchen/docker_test:1.4.1
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/zuoxuchen/docker_test]
2653d992f4ef: Pushed
1.4.1: digest: sha256:f2b94498db210d953f8be571d395bb737988c69aa5683f959d437a5a9573f158 size: 529
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zuoxuchen_centos 1.4 57c8e3e58d02 7 minutes ago 209MB
registry.cn-hangzhou.aliyuncs.com/zuoxuchen/docker_test 1.4.1 57c8e3e58d02 7 minutes ago 209MB
centos latest 300e315adb2f 4 months ago 209MB
在阿里云中查看是否存在正确的镜像文件;
配置完成,Docker基础内容完毕!