Docker镜像推送(push)到Docker Hub

时间:2023-11-19 13:21:32

镜像构建成功后,只要有docker环境就可以使用,但必须将镜像推送到Docker Hub上去。我们之前创建的镜像不符合Docker Hub的tag要求,因为 在Docker Hub注册的用户名是boonyadocker而不是boonya,所以需要docker tag进行修改,最后利用docker push命令推送镜像到公共仓库。

Docker hub注册用户

到官网注册账号:https://hub.docker.com/

在本地Linux登录docker:

docker login

输入用户名密码进行登录:

docker@default:~$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: boonyadocker
Password:
Login Succeeded
docker@default:~$

tag修改镜像名称

推送镜像的规范是:

docker push 注册用户名/镜像名  

tag命令修改为规范的镜像:

[root@localhost tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xtjatswc/mycore latest 73ce3cd97c01 About an hour ago 1.74GB
microsoft/dotnet latest 521411f3b61d 4 days ago 1.73GB
[root@localhost tmp]# docker tag xtjatswc/mycore:latest xtjatswc/mycore2:v3
[root@localhost tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xtjatswc/mycore2 v3 73ce3cd97c01 About an hour ago 1.74GB
xtjatswc/mycore latest 73ce3cd97c01 About an hour ago 1.74GB
microsoft/dotnet latest 521411f3b61d 4 days ago 1.73GB
[root@localhost tmp]#

推送镜像到Docker Hub

通过push命令推送镜像:

docker push xtjatswc/mycore2:v3  

Docker镜像推送(push)到Docker Hub

注:推送Docker Hub速度很慢,耐心等待,很有可能失败,失败会尝试多次重传,之后断开推送(但已推送上去的会保留,保留时间不知道是多久)。

访问Docker Hub发布镜像就不用多说了,很简单