Docker+NETCore系列文章(五、推送自制镜像到Docker Hub、阿里云镜像仓库)

推送镜像到Docker Hub镜像仓库

1、访问Docker Hub:https://hub.docker.com/,注册并登陆Docker。

2、使用docker pull hello-world命令拉取hello-workld镜像。

[root@VM-0-6-centos ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

3、执行docker images命令查看当前是否存在hello-world镜像。

[root@VM-0-6-centos ~]# docker images
REPOSITORY                                                      TAG               IMAGE ID       CREATED       SIZE
hello-world                                                     latest            d1165f221234   4 weeks ago   13.3kB

4、执行docker tag 本地镜像:版本号 你的docker账号名/推送的镜像名:版本号

[root@VM-0-6-centos ~]# docker tag hello-world:latest xgytop/hello-world:v1

5、执行docker login -u 注册DockerHub的账号 -p "DockerHub密码",看到“Login Succeeded”则表示登陆成功。

[root@VM-0-6-centos ~]# docker login -u 注册DockerHub的账号  -p "DockerHub密码"
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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

6、执行docker push 你的docker账号名/推送的镜像名:版本号推送本地的镜像到Docker Hub仓库。

[root@VM-0-6-centos ~]# docker push xgytop/hello-world:v1
The push refers to repository [docker.io/xgytop/hello-world]
f22b99068db9: Mounted from library/hello-world 
v1: digest: sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792 size: 525

7、刷新Docker Hub仓库,可看到如下图所示镜像推送成功:
在这里插入图片描述
在这里插入图片描述

推送镜像到阿里云镜像仓库

1、访问阿里云镜像管理中心:https://cr.console.aliyun.com。
在这里插入图片描述
2、点击“默认实例”->“仓库管理”->“命名空间”,创建一个名为“xgy-hub”的命名空间。
在这里插入图片描述
3、点击“仓库管理”->“镜像仓库”->“创建镜像仓库”,创建一个名为“xgy-docker”的镜像仓库,并选择“本地仓库”。
在这里插入图片描述
在这里插入图片描述
4、点击上一步创建的“xgy-docker”仓库,可看到如下图所示的步骤,按照下面的步骤即可进行镜像的拉取和推送操作。
在这里插入图片描述
5、执行sudo docker login --username=你的用户名 registry.cn-shenzhen.aliyuncs.com -p 你的阿里云登陆密码命令,看到“Login Succeeded”则表示登陆成功。看到“unauthorized: authentication required”则表示登陆密码错误。

[root@VM-0-6-centos ~]# sudo docker login --username=你的用户名 registry.cn-shenzhen.aliyuncs.com -p 你的阿里云登陆密码
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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

6、执行sudo docker tag [镜像id] registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker:[镜像版本号]标记镜像。

[root@VM-0-6-centos ~]# sudo docker tag d1165f221234  registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker:v1

7、执行sudo docker push registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker:[镜像版本号]将镜像推送到阿里云镜像仓库。下面样式推送hello-world的v1和v2版本。

[root@VM-0-6-centos ~]# sudo docker push registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker:v1
The push refers to repository [registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker]
f22b99068db9: Pushed 
v1: digest: sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792 size: 525
[root@VM-0-6-centos ~]# sudo docker tag d1165f221234  registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker:v2
[root@VM-0-6-centos ~]# sudo docker push registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker:v2
The push refers to repository [registry.cn-shenzhen.aliyuncs.com/xgy-hub/xgy-docker]
f22b99068db9: Layer already exists 
v2: digest: sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792 size: 525
[root@VM-0-6-centos ~]# 

8、点击“镜像仓库”->“镜像版本”,可看到推送到阿里云的两个版本镜像信息。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40600379/article/details/115454763