Docker | 发布镜像到镜像仓库

本文记录发布镜像到 DockerHub阿里云镜像仓库。工作中使用的是JFrog ArtifactoryHarbor,没有太大差别。

发布镜像到DockerHub

https://hub.docker.com/ 注册账号

1、登录docker

[root@--- ~]# docker login --help

Usage:  docker login [OPTIONS] [SERVER]

Log in to a Docker registry.
If no server is specified, the default is defined by the daemon.

Options:
  -p, --password string   Password
      --password-stdin    Take the password from stdin
  -u, --username string   Username
[root@--- ~]# 
[root@--- ~]# docker login -u xiaobluewhale
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@--- ~]# 

2、服务器上提交镜像

docker push [OPTIONS] NAME[:TAG]

docker push 命令推送镜像的规范是:注册用户名/镜像名。

使用以下方法之一命名您的本地镜像:

  1. 当你构建它们时,使用如下命令
docker build -t <hub-user>/<repo-name>[:<tag>]
  1. 重命名现有的本地镜像
docker tag <existing-image> <hub-user>/<repo-name>[:<tag>]
  1. docker commit 提交更改
docker commit <existing-container> <hub-user>/<repo-name>[:<tag>]
  1. 推送镜像仓库
docker push <hub-user>/<repo-name>:<tag>
  • docker push xiao/tomcat
docker push xiao/tomcat
Using default tag: latest
The push refers to repository [docker.io/xiao/tomcat]
69421fc728fb: Preparing 
1f6217f0c2bb: Preparing 
aa9c3f9fafec: Preparing 
7d4a4cd414a9: Preparing 
74ddd0ec08fa: Preparing 
denied: requested access to the resource is denied 

推送失败,被拒绝

推送失败的原因: name必须是注册用户名

解决push失败问题

增加一个tag, 重命名镜像

# 增加tag,重命名镜像
docker tag 24b3a476f143 xiaobluewhale/tomcat:1.0
The push refers to repository [docker.io/xiaobluewhale/tomcat]

# 查看镜像
docker images
REPOSITORY            TAG       IMAGE ID       CREATED        SIZE
xiaobluewhale/tomcat   1.0       24b3a476f143   13 hours ago   680MB
xiao/tomcat            1.0       24b3a476f143   13 hours ago   680MB
xiao/tomcat            latest    24b3a476f143   13 hours ago   680MB

# 推送镜像
docker push xiaobluewhale/tomcat:1.0

提交成功

提交的时候也是按照镜像的层级提交的

在个人DockerHub上查看推送成功的镜像

发布镜像到阿里云镜像仓库

1、登陆阿里云

2、找到容器镜像服务,创建实例

企业版需要付费购买(1个月741)

我选择创建个人实例

3、创建命名空间(为了隔离)

4、创建镜像仓库

本地

5、推送镜像

参考阿里云容器镜像指南

  1. 登录
docker login --username=[yourname] registry.cn-hangzhou.aliyuncs.com
  1. 查看镜像
docker images
REPOSITORY                      TAG       IMAGE ID       CREATED        SIZE
xiaobluewhale/tomcat            1.0       24b3a476f143   14 hours ago   680MB
  1. 推送镜像
docker push xiaobluewhale/tomcat:1.0
The push refers to repository [docker.io/xiaobluewhale/tomcat]

6、阿里云查看镜像

imageID: 24b3a476f143

也可以查看可视化的层信息


我是 甜点cc

热爱前端,也喜欢专研各种跟本职工作关系不大的技术,技术、产品兴趣广泛且浓厚,等待着一个创业机会。本号主要致力于分享个人经验总结,希望可以给一小部分人一些微小帮助。

希望能和大家一起努力营造一个良好的学习氛围,为了个人和家庭、为了我国的互联网物联网技术、数字化转型、数字经济发展做一点点贡献。数风流人物还看中国、看今朝、看你我。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Docker Buildx 是 Docker 提供的一个命令行工具,用于构建、打包和发布 Docker 镜像。要将 Docker Buildx 同步镜像到其他仓库,可以按照以下步骤进行操作: 1. 首先,确保已安装 Docker Buildx。可以通过运行以下命令检查版本: ``` docker buildx version ``` 2. 确认已登录到要同步的目标镜像仓库。可以使用 Docker 的登录命令: ``` docker login <registry_url> ``` 3. 创建一个基于 Buildx 构建的建议。(这一步是可选的,如果已存在已配置好的构建器,则可以跳过此步骤): ``` docker buildx create --use ``` 4. 使用 Docker Buildx 构建镜像并将其推送到目标仓库。可以使用以下命令: ``` docker buildx build --platform <platform> -t <image_name> --push <path_to_dockerfile> ``` 其中,`<platform>` 指定构建的目标平台(例如 linux/amd64、linux/arm64、linux/arm/v7 等),`<image_name>` 指定要构建的镜像名称,`<path_to_dockerfile>` 指定 Dockerfile 的路径。 例如,要构建一个适用于 linux/amd64 平台的镜像并推送到目标仓库,可以使用以下命令: ``` docker buildx build --platform linux/amd64 -t <registry_url>/<image_name> --push <path_to_dockerfile> ``` 这将构建镜像并将其推送到目标仓库中。 5. 在同步完成后,可以使用目标仓库的相关命令(如 `docker pull`)从其他位置访问这个镜像。 通过以上步骤,我们可以使用 Docker Buildx 将镜像同步到其他仓库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

甜点cc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值