【Docker】从零开始:9.Docker命令:Push推送仓库(Docker Hub,阿里云)

【Docker】从零开始:9.Docker命令:Push推送仓库

知识点

1.Docker Push有什么作用?

Docker Push是Docker的一个命令,用于将本地的Docker镜像推送到仓库中。

2.Docker仓库有哪几种

2.1 公有仓库

  • 公有仓库一般指的是Docker Hub 是 Docker 公司维护的公有 Registry。
  • 在 Docker 公有仓库中,用户可以找到各种类型的 Docker 镜像,例如常用的操作系统镜像、Web 服务器镜像、数据库镜像等。在使用 Docker 时,通常需要先从公有仓库中下载所需的 Docker 镜像,然后使用这些镜像来创建 Docker 容器(container)。
  • 除了从 Docker 公有仓库中下载镜像,用户也可以在本地构建镜像并上传到 Docker 公有仓库进行分享。Docker 公有仓库对于上传的镜像有一些限制,例如镜像大小不能超过 2 GB,同时需要遵守一定的容器镜像编写规范。
  • 总之,Docker 公有仓库是 Docker 用户不可或缺的资源之一,用户可以在其中找到并下载、分享各种类型的 Docker 镜像,使得 Docker 应用开发和部署更加便捷高效。

2.2 第三方仓库

  • 指的是非官方的仓库,比如阿里云,腾讯的docker仓库
  • Docker第三方仓库也可以分为公共仓库和私有仓库两种。用户可以在其中查找和下载Docker镜像。

2.3 私有仓库

  • 私有仓库则是用户自己搭建的仓库,可以用于存储和分享自己的Docker镜像。

2.4 搭建私有仓库的方法有哪几种

  1. registry镜像搭建本地私有仓库
  2. harbor搭建私有仓库
  3. 注册使用第三方私有仓库

3.Docker公有仓库与私有仓库的优缺点对比

  • Docker仓库分为公有仓库和私有仓库,它们之间有一些明显的区别。
  1. 定义和访问权限:公有仓库是Docker官方提供的公共仓库,称为Docker Hub,它对所有人开放,用户可以在其中创建帐户,存储和共享Docker镜像。而私有仓库是由用户自己搭建、管理和维护的仓库,它只对特定的用户或团队开放,可以根据需要进行访问权限的设置。
  2. 存储位置和数据安全性:公有仓库中的镜像存储在公共服务器上,用户无需担心存储空间和数据安全性的问题。而私有仓库则是由用户自己选择存储位置,可以部署在本地服务器或云存储平台上,对于数据安全性的保障更加灵活。
  3. 集成和定制性:公有仓库中的镜像通常是由第三方开发者提供的,用户可以直接使用或进行二次定制。而私有仓库则可以根据用户的需求进行定制,可以与其他项目无缝集成,同时也可以根据业务需要进行扩展和定制。
  4. 使用费用:使用Docker Hub等公有仓库时,一般不需要支付任何费用,除非需要使用高级功能或大量存储空间。而搭建和使用私有仓库可能需要一定的成本,包括服务器硬件、存储空间、网络带宽等费用。

总之,公有仓库和私有仓库各有优缺点,用户可以根据实际需求选择适合自己的仓库类型。

Docker Push 命令

标准语法

bash 复制代码
docker push [OPTIONS] NAME[:TAG]

操作参数

参数 描述
--disable-content-trust 禁用内容信任,不对推送的镜像进行签名。
--platform 指定要推送的镜像所在的平台。

推送Docker Hub(公有仓库)

1.注册Docker Hub账号并登录登录(免费)

注册地址: https://hub.docker.com/

2.按图示操作找到仓库按钮

3.创建自己的仓库


4.创建成功并查看自己的仓库

5.用命令登录仓库

bash 复制代码
[root@docker ~]# docker login
Log in with your Docker ID or email address 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.
You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/

Username: circledba
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@docker ~]# 

6.找到要推送的镜像。并重命名

bash 复制代码
[root@docker ~]# docker images
REPOSITORY      TAG       IMAGE ID       CREATED         SIZE
cirlce/ubuntu   1.0       4eac314fbf24   5 hours ago     72.8MB
mysql           5.6       dd3b2a5dcb48   23 months ago   303MB
ubuntu          latest    ba6acccedd29   2 years ago     72.8MB
hello-world     latest    feb5d9fea6a5   2 years ago     13.3kB
[root@docker ~]# [root@docker ~]# docker tag cirlce/ubuntu:1.0 circledba/kingbase-es:test
[root@docker ~]# docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
circledba/kingbase-es   test      4eac314fbf24   5 hours ago     72.8MB
cirlce/ubuntu           1.0       4eac314fbf24   5 hours ago     72.8MB
mysql                   5.6       dd3b2a5dcb48   23 months ago   303MB
ubuntu                  latest    ba6acccedd29   2 years ago     72.8MB
hello-world             latest    feb5d9fea6a5   2 years ago     13.3kB
[root@docker ~]# 

7.推送到Docker Hub仓库

bash 复制代码
[root@docker ~]# docker push circledba/kingbase-es:test
The push refers to repository [docker.io/circledba/kingbase-es]
9f54eef41275: Mounted from library/ubuntu 
test: digest: sha256:1dec09d8edcd108ab0d17dc25f2c729790118c2f91512b5e492bd646c45a1051 size: 529
[root@docker ~]# 

8.验证的Docker镜像是否推送成功

在这已经看到我们推送成功了

9.退出远程仓库

bash 复制代码
[root@docker ~]# docker logout
Removing login credentials for https://index.docker.io/v1/
[root@docker ~]# 

推送到阿里云仓库

1.注册阿里云账号并登录(或者用淘宝登录)

2.点击控制台并找到容器




3.创建自己的仓库




4. 创建仓库成功

5.用命令方式登录阿里云

bash 复制代码
[root@docker ~]# docker login --username=caviroye@qq.com registry.cn-hangzhou.aliyuncs.com
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@docker ~]# docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
circledba/kingbase-es   test      4eac314fbf24   6 hours ago     72.8MB
cirlce/ubuntu           1.0       4eac314fbf24   6 hours ago     72.8MB
mysql                   5.6       dd3b2a5dcb48   23 months ago   303MB
ubuntu                  latest    ba6acccedd29   2 years ago     72.8MB
hello-world             latest    feb5d9fea6a5   2 years ago     13.3kB
[root@docker ~]#

6.找到要推送的镜像。并重命名

bash 复制代码
[root@docker ~]# docker tag 4eac314fbf24 registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es:test
[root@docker ~]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED         SIZE
circledba/kingbase-es                                      test      4eac314fbf24   6 hours ago     72.8MB
cirlce/ubuntu                                              1.0       4eac314fbf24   6 hours ago     72.8MB
registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es   test      4eac314fbf24   6 hours ago     72.8MB
mysql                                                      5.6       dd3b2a5dcb48   23 months ago   303MB
ubuntu                                                     latest    ba6acccedd29   2 years ago     72.8MB
hello-world                                                latest    feb5d9fea6a5   2 years ago     13.3kB
[root@docker ~]# 

7.推送到Docker Hub仓库

bash 复制代码
[root@docker ~]# docker push registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es:test
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es]
9f54eef41275: Pushed 
test: digest: sha256:1dec09d8edcd108ab0d17dc25f2c729790118c2f91512b5e492bd646c45a1051 size: 529
[root@docker ~]# 

8.验证的Docker镜像是否推送成功

在这已经看到我们推送成功了

9.退出远程仓库

bash 复制代码
[root@docker ~]# docker logout registry.cn-hangzhou.aliyuncs.com
Removing login credentials for registry.cn-hangzhou.aliyuncs.com
[root@docker ~]# 

10.删除我们的镜像 尝试从阿里云下载镜像

bash 复制代码
[root@docker ~]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED         SIZE
cirlce/ubuntu                                              1.0       4eac314fbf24   7 hours ago     72.8MB
registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es   test      4eac314fbf24   7 hours ago     72.8MB
circledba/kingbase-es                                      test      4eac314fbf24   7 hours ago     72.8MB
mysql                                                      5.6       dd3b2a5dcb48   23 months ago   303MB
ubuntu                                                     latest    ba6acccedd29   2 years ago     72.8MB
hello-world                                                latest    feb5d9fea6a5   2 years ago     13.3kB
[root@docker ~]# docker rmi registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es:test
Untagged: registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es:test
Untagged: registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es@sha256:1dec09d8edcd108ab0d17dc25f2c729790118c2f91512b5e492bd646c45a1051
[root@docker ~]# 
[root@docker ~]# 
[root@docker ~]# docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
cirlce/ubuntu           1.0       4eac314fbf24   7 hours ago     72.8MB
circledba/kingbase-es   test      4eac314fbf24   7 hours ago     72.8MB
mysql                   5.6       dd3b2a5dcb48   23 months ago   303MB
ubuntu                  latest    ba6acccedd29   2 years ago     72.8MB
hello-world             latest    feb5d9fea6a5   2 years ago     13.3kB
[root@docker ~]# docker pull registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es:test
test: Pulling from circle2023/kingbase-es
Digest: sha256:1dec09d8edcd108ab0d17dc25f2c729790118c2f91512b5e492bd646c45a1051
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es:test
registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es:test
[root@docker ~]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED         SIZE
circledba/kingbase-es                                      test      4eac314fbf24   7 hours ago     72.8MB
cirlce/ubuntu                                              1.0       4eac314fbf24   7 hours ago     72.8MB
registry.cn-hangzhou.aliyuncs.com/circle2023/kingbase-es   test      4eac314fbf24   7 hours ago     72.8MB
mysql                                                      5.6       dd3b2a5dcb48   23 months ago   303MB
ubuntu                                                     latest    ba6acccedd29   2 years ago     72.8MB
hello-world                                                latest    feb5d9fea6a5   2 years ago     13.3kB
[root@docker ~]# 
相关推荐
倪某某21 分钟前
阿里云无影GPU部署WAN2.2模型
阿里云·云计算
阿里云通信41 分钟前
WhatsApp 账号被封怎么办?日常“养号”、防封、解封实践
阿里云·whatsapp·whatsapp 封号
菜鸟思维1 小时前
优化NextJs 项目的Docker 镜像 从3.62G 优化到 296.85M
docker
倪某某1 小时前
阿里云ECS GPU部署WAN2.2
人工智能·阿里云·云计算
怣疯knight1 小时前
Docker Desktop 4.55.0版本安装成功教程
windows·docker
东方佑2 小时前
使用Docker Compose一键部署OnlyOffice:完整指南与配置解析
运维·docker·容器
赵文宇(温玉)2 小时前
Docker的价值、特点、创新与关键技术
运维·docker·容器
风吹落叶花飘荡2 小时前
将mysql数据库的内容备份至阿里云 oss归档存储
数据库·mysql·阿里云
小白考证进阶中4 小时前
阿里云ACA认证常见问题答疑
阿里云·大模型·云计算·阿里云aca证书·阿里云aca·aca认证·入门证书
Coder码匠4 小时前
Docker Compose 部署 Spring Boot 应用完全指南
spring boot·docker·容器