1 登录阿里云

登录阿里云 >> 进入控制台 >> 搜索容器镜像服务

https://cr.console.aliyun.com/cn-hangzhou/instances

创建个人实例(上图已创建)>> 进入个人实例

创建命名空间

使用命名空间创建仓库(一个仓库对应一个docker镜像)>> 提交时选择本地仓库 >> 在镜像仓库列表点击管理操作(操作指南)

 

 

2 创建测试镜像

以redis:3.2拉取镜像,创建并启动容器,根据容器commit新的镜像myredis:1.0.0,对这个新镜像进行测试。

拉取镜像:

[root@localhost ~]# docker pull redis:3.2
3.2: Pulling from library/redis
f17d81b4b692: Pull complete
b32474098757: Pull complete
8980cabe8bc2: Pull complete
58af19693e78: Pull complete
a977782cf22d: Pull complete
9c1e268980b7: Pull complete
Digest: sha256:7b0a40301bc1567205e6461c5bf94c38e1e1ad0169709e49132cafc47f6b51f3
Status: Downloaded newer image for redis:3.2
docker.io/library/redis:3.2
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
redis        3.2       87856cc39862   2 years ago   76MB
[root@localhost ~]#

运行容器:

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
redis        3.2       87856cc39862   2 years ago   76MB
[root@localhost ~]# docker run -d 87856cc39862
bc3c0cb4fbb094d838ad6f0989a3657a56240819b779b89681db91016b59e11c
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS      NAMES
bc3c0cb4fbb0   87856cc39862   "docker-entrypoint.s…"   4 seconds ago   Up 3 seconds   6379/tcp   vibrant_khayyam

提交新的镜像

# -a 作者
# -m 备注
[root@localhost ~]# docker commit -a tech -m "myredis message" bc3c0cb4fbb0 myredis:1.0
sha256:d0358c235464dcf848034bda3c1291e3c72d2f9911cfb26913d9e6786d8ffab4
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
myredis      1.0       d0358c235464   7 seconds ago   76MB
redis        3.2       87856cc39862   2 years ago     76MB

3 推送测试镜像

根据根据第一步的操作指南,先登录阿里云,再对镜像myredis标记tag,再push;

登录阿里云

[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

标记tag

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
myredis      1.0       d0358c235464   5 minutes ago   76MB
redis        3.2       87856cc39862   2 years ago     76MB
[root@localhost ~]# docker tag d0358c235464 registry.cn-hangzhou.aliyuncs.com/alytech/myredis:1.0.0
[root@localhost ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED         SIZE
myredis                                             1.0       d0358c235464   5 minutes ago   76MB
registry.cn-hangzhou.aliyuncs.com/alytech/myredis   1.0.0     d0358c235464   5 minutes ago   76MB
redis                                               3.2       87856cc39862   2 years ago     76MB

推送registry.cn-hangzhou.aliyuncs.com/alytech/myredis

[root@localhost ~]# docker push registry.cn-hangzhou.aliyuncs.com/alytech/myredis:1.0.0
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/alytech/myredis]
56431c543d6c: Pushed
bb617143299d: Pushed
cfe17e3394d7: Pushed
aa1a19279a9a: Pushed
197ffb073b01: Pushed
237472299760: Pushed
1.0.0: digest: sha256:778737cdc341f83f47c27b5bc21a2df1a851a0e263f2697bd638fc9c8f1cb6ab size: 1571
[root@localhost ~]#

推送成功

删除本地镜像pull进行测试

[root@localhost ~]# docker rm $(docker ps -qa) -f
bc3c0cb4fbb0
[root@localhost ~]# docker rmi $(docker images -q) -f
Untagged: redis:3.2
Untagged: redis@sha256:7b0a40301bc1567205e6461c5bf94c38e1e1ad0169709e49132cafc47f6b51f3
Deleted: sha256:87856cc39862cec77541d68382e4867d7ccb29a85a17221446c857ddaebca916
Deleted: sha256:6650bf9ad80dc21652fb0a98eb55be7a30a860fbb0b76b2a542ee0af4111b890
Deleted: sha256:9a7166b18cebf0cff5d029c76f0104abb28b37a75e540d152a3165ea34bb77bb
Deleted: sha256:cf1be06e96098c6a378519ceb223d87a04f2a556df061bde1003db5f43337912
Deleted: sha256:7ae66985fd3a3a132fab51b4a43ed32fd14174179ad8c3041262670523a6104c
Deleted: sha256:bf45690ef12cc54743675646a8e0bafe0394706b7f9ed1c9b11423bb5494665b
Deleted: sha256:237472299760d6726d376385edd9e79c310fe91d794bc9870d038417d448c2d5
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@localhost ~]# docker pull registry.cn-hangzhou.aliyuncs.com/alytech/myredis:1.0.0
1.0.0: Pulling from alytech/myredis
f17d81b4b692: Pull complete
b32474098757: Pull complete
8980cabe8bc2: Pull complete
58af19693e78: Pull complete
a977782cf22d: Pull complete
9c1e268980b7: Pull complete
Digest: sha256:778737cdc341f83f47c27b5bc21a2df1a851a0e263f2697bd638fc9c8f1cb6ab
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/alytech/myredis:1.0.0
registry.cn-hangzhou.aliyuncs.com/alytech/myredis:1.0.0
[root@localhost ~]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED          SIZE
registry.cn-hangzhou.aliyuncs.com/alytech/myredis   1.0.0     d0358c235464   11 minutes ago   76MB

拉取成功

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐