背景介绍
Docker镜像构建成功后,只要有docker环境就可以使用,但必须将镜像推送到Docker Hub上去。创建的镜像最好要符合Docker Hub的tag要求,因为在Docker Hub注册的用户名是liboware,最后利用docker push命令推送镜像到公共仓库。
前提概要
你需要在Docker hub注册用户:到官网注册账号:hub.docker.com/
例如:注册账号名称:liboware
在本地服务器登录docker:
例如在CentOS7服务器
[root ~]# 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: liboware ##输入账号
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
查看镜像
[]
REPOSITORY TAG IMAGE ID CREATED SIZE
nacos v1 9e5f6711d527 3 days ago 178MB
mysql v1 9e5f6711d527 3 days ago 178MB
docker tag建立镜像
[]
docker images 查看镜像
[]
REPOSITORY TAG IMAGE ID CREATED SIZE
nacos v1 9e5f6711d527 3 days ago 178MB
nginx v1 9e5f6711d527 3 days ago 178MB
liboware/mysql v1 9e5f6711d527 3 days ago 178MB
[]
docker hub推送镜像
docker push 注册docker用户名/REPOSITORY:TAG
[root@localhost ~]
The push refers to repository [docker.io/llxxyy/nginx-io]
833a0f6a6ff9: Pushed
10bfe402500e: Pushed
d43641d7d594: Mounted from library/nginx
c2adabaecedb: Mounted from library/nginx
v1: digest: sha256:67dcdae5578c0374019cc899731543cfd7c48fe5780e84233a258f2bf7d2ceda size: 1155
[root@localhost ~]
注:推送Docker Hub速度很慢,耐心等待,很有可能失败,失败会尝试多次重传,之后断开推送(但已推送上去的会保留,保留时间不知道是多久)。
hub docker效果
Docker 使用发布的镜像
docker@default:~$ docker search liboware/nacos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
liboware/nacos In this image server you can use ma... 0
在pull下来
[root@localhost ~]
v1: Pulling from liboware/nacos
Digest: sha256:67dcdae5578c0374019cc899731543cfd7c48fe5780e84233a258f2bf7d2ceda
Status: Downloaded newer image for liboware/nacos:v1
docker.io/liboware/nacos:v2
确认pull成功
[root@localhost ~]
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx stable-perl 9e5f6711d527 3 days ago 178MB
nginx v1 9e5f6711d527 3 days ago 178MB
libo/nacos v1 9e5f6711d527 3 days ago 178MB
遇到的问题
- 执行:docker push nacos:v1【提示denied: requested access to the resource is denied】
- 我们可以列出所有镜像:docker images
- 建立tag将要发布的镜像改到自己账户名下,我的账户名:liboware
docker tag nacos:v2 liboware/nacos:v2
- 再次推送:docker push liboware/nacos:v2【成功】
分享资源
获取以上资源请访问开源项目 点击跳转