用Docker发布自己的镜像

简介: 用Docker发布自己的镜像

发布自己的镜像
DockerHub
1、地址:https://hub.docker.com/注册自己的账号

image.png

2、确定这个账号可以登录

3、在这个服务器上提交自己的镜像

# centos7环境
root@localhost test]#  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@localhost test]# docker login -u bruceliu1973
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

4、登录完毕,可以提交镜像,执行docker push命令

# 在centos7环境执行,但是出现一个问题
[root@localhost test]# docker push diytomcat
Using default tag: latest
The push refers to repository [docker.io/library/diytomcat]
41597dc9883c: Preparing
ba91795798ac: Preparing
43b27989aa87: Preparing
9445929b0a14: Preparing
74ddd0ec08fa: Preparing
denied: requested access to the resource is denied

# 解决push镜像的问题
# 给镜像增加一个tag
# 语法,[root@localhost test]#docker tag 容器id username/imagename   *****username 是dockerhub用户名,imagename是镜像名, imagename一定跟要push的镜像名一样,否则还是被拒绝
[root@localhost test]# docker tag 66f61ab160f4 bruceliu1973/diytomcat:1.0

# 修改为username/imagename:tag格式,push成功,如下图
[root@localhost tomcat]# docker push bruceliu1973/diytomcat:1.0
The push refers to repository [docker.io/bruceliu1973/diytomcat]
41597dc9883c: Pushed
ba91795798ac: Pushed
43b27989aa87: Pushed
9445929b0a14: Pushed
74ddd0ec08fa: Pushed
1.0: digest: sha256:f37ddc8c0333224c1e5a98588469919bad63aa5632722977c56720718e6886f5 size: 1372

image.png

注意:提交的时候也是按照镜像的层级来进行提交的。

阿里云镜像服务
1、登录阿里云

2、找到容器镜像服务(https://cr.console.aliyun.com/cn-hangzhou/instances)

3、创建命名空间

image.png

4、创建容器镜像
image.png

5、浏览阿里云

点击仓库,看到里面有一些基本信息。

image.png

# 登录阿里云
[root@localhost ~]# docker login --username=bruce刘晓伟 registry.cn-hangzhou.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.  # 宿主机这里存储用户名和密码,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 tag[ImageId] registry.cn-hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:[镜像版本号]
# 本例
[root@localhost ~]# docker tag[ImageId] registry.cn-  hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:66f61ab160f4
# docker push,严格按照阿里云镜像推送命令格式执行,否则会被拒绝
[root@localhost ~]# docker push bruceliu1973/diytomcat:1.0  # 这个命令格式传DockerHub可以,传阿里云拒绝
# 按照阿里云格式推送到Registry,[镜像版本号]为上一步骤生成的版本号,此例为1.0,不是imageId
[root@localhost ~]# docker tag[ImageId] registry.cn-hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:[镜像版本号] 
# 实际操作命令格式
[root@localhost ~]# docker push registry.cn-hangzhou.aliyuncs.com/bruce_liu1973/bruce_liuxiaowei:1.0

image.png
image.png

总结:阿里云容器镜像参考并严格按照官方文档格式执行命令。

以后如果想让自己的网站被大家访问,就可以把网站镜像发到阿里云或者DockerHub,然后大家pull—run— OK

小结:
image.png

镜像打包成一个tar压缩包,可以发送压缩包给别人,涉及到两个命令

[root@localhost ~]# docker save --help
Usage:  docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Options:
  -o, --output string   Write to a file, instead of STDOUT
相关文章
|
11天前
|
存储 运维 应用服务中间件
Docker Image即Docker镜像
Docker 镜像是 Docker 容器的基础,包含了运行应用程序所需的一切。通过 Dockerfile 可以方便地创建自定义镜像,并且利用 Docker 提供的命令可以轻松管理和使用这些镜像。掌握 Docker 镜像的创建、管理和使用,是进行容器化应用开发和部署的基础技能。希望本文能帮助读者更好地理解 Docker 镜像的概念和操作,提高开发和运维效率。
68 13
|
24天前
|
消息中间件 Kafka 流计算
docker环境安装kafka/Flink/clickhouse镜像
通过上述步骤和示例,您可以系统地了解如何使用Docker Compose安装和配置Kafka、Flink和ClickHouse,并进行基本的验证操作。希望这些内容对您的学习和工作有所帮助。
147 28
|
2月前
|
Ubuntu NoSQL 开发工具
《docker基础篇:4.Docker镜像》包括是什么、分层的镜像、UnionFS(联合文件系统)、docker镜像的加载原理、为什么docker镜像要采用这种分层结构呢、docker镜像commit
《docker基础篇:4.Docker镜像》包括是什么、分层的镜像、UnionFS(联合文件系统)、docker镜像的加载原理、为什么docker镜像要采用这种分层结构呢、docker镜像commit
248 70
|
11天前
|
JavaScript Shell C#
多种脚本批量下载 Docker 镜像:Shell、PowerShell、Node.js 和 C#
本项目提供多种脚本(Shell、PowerShell、Node.js 和 C#)用于批量下载 Docker 镜像。配置文件 `docker-images.txt` 列出需要下载的镜像及其标签。各脚本首先检查 Docker 是否安装,接着读取配置文件并逐行处理,跳过空行和注释行,提取镜像名称和标签,调用 `docker pull` 命令下载镜像,并输出下载结果。使用时需创建配置文件并运行相应脚本。C# 版本需安装 .NET 8 runtime。
81 1
|
1月前
|
网络协议 Linux 网络安全
docker centos镜像 npm安装包时报错“npm ERR! code ECONNRESET”
通过上述步骤,您可以有效解决在 Docker 中使用 CentOS 镜像安装 npm 包时遇到的 "npm ERR! code ECONNRESET" 错误。希望这些方法能帮助您顺利进行 npm 包的安装。
138 26
|
2月前
|
存储 Docker 容器
Docker-基础(数据卷、自定义镜像、Compose)
通过数据卷实现持久化存储,通过自定义镜像满足特定需求,通过Docker Compose方便地管理多容器应用
98 27
|
2月前
|
Ubuntu NoSQL Linux
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
215 6
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
|
2月前
|
Ubuntu NoSQL 关系型数据库
《docker基础篇:6.本地镜像发布到私有库》包括本地镜像发布到私有库流程、docker regisry是什么、将本地镜像推送到私有库
《docker基础篇:6.本地镜像发布到私有库》包括本地镜像发布到私有库流程、docker regisry是什么、将本地镜像推送到私有库
142 29
|
2月前
|
存储 Docker 容器
Docker-基础(数据卷、自定义镜像、Compose)
通过数据卷实现持久化存储,通过自定义镜像满足特定需求,通过Docker Compose方便地管理多容器应用。掌握这些Docker基础概念和操作,可以显著提高开发和部署效率,确保应用程序的可移植性和可扩展性。
84 22
|
3月前
|
Docker 容器
将本地的应用程序打包成Docker镜像
将本地的应用程序打包成Docker镜像