背景介绍
Docker 镜像构建成功后,只要有 docker 环境就可以使用,但必须将镜像推送到 Docker Hub 上去。创建的镜像最好要符合 Docker Hub 的 tag 要求,因为在 Docker Hub 注册的用户名是 liboware,最后利用 docker push 命令推送镜像到公共仓库。
前提概要
你需要在 Docker hub 注册用户:到官网注册账号:https://hub.docker.com/
例如:注册账号名称:liboware
在本地服务器登录 docker:
例如在 CentOS7 服务器
[root@localhost ~]# 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
复制代码
查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nacos v1 9e5f6711d527 3 days ago 178MB
mysql v1 9e5f6711d527 3 days ago 178MB
复制代码
docker tag 建立镜像
[root@localhost ~]# docker tag nacos:v1 liboware/nacos:v1
复制代码
docker images 查看镜像
[root@localhost ~]# 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
[root@localhost ~]#
复制代码
docker hub 推送镜像
docker push 注册 docker 用户名/REPOSITORY:TAG
[root@localhost ~]# docker push liboware/nacos:v1
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 ~]# docker pull liboware/nacos:v1
v1: Pulling from liboware/nacos
Digest: sha256:67dcdae5578c0374019cc899731543cfd7c48fe5780e84233a258f2bf7d2ceda
Status: Downloaded newer image for liboware/nacos:v1
docker.io/liboware/nacos:v2
复制代码
确认 pull 成功
[root@localhost ~]# docker images
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【成功】
评论