用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
相关文章
|
8月前
|
JavaScript Docker 容器
使用Docker多阶段构建优化镜像大小
使用Docker多阶段构建优化镜像大小
534 100
|
8月前
|
缓存 安全 Linux
优化Docker镜像大小的多阶段构建实践
优化Docker镜像大小的多阶段构建实践
531 99
|
8月前
|
缓存 Docker 容器
优化Docker镜像大小的五个实用技巧
优化Docker镜像大小的五个实用技巧
805 98
|
8月前
|
安全 Go Docker
使用Docker多阶段构建优化镜像大小
使用Docker多阶段构建优化镜像大小
|
Docker 容器 Perl
云效flow构建docker镜像更换apt源为阿里镜像源
在 Dockerfile 中添加命令以更换 Debian 源为阿里云镜像,加速容器内软件包下载。核心命令通过 `sed` 实现源地址替换,并更新 apt 软件源。其中 `cat` 命令用于验证替换是否成功,实际使用中可删除该行。
2948 32
|
7月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
849 6
|
10月前
|
Docker 容器 应用服务中间件
Docker 客户端是如何拉取镜像的?
Docker客户端拉取镜像的过程遵循Docker Registry HTTP API V2规范,主要分为解析镜像名、鉴权、获取Manifest、拉取Layers及本地合并五个步骤。它与Docker Hub、Harbor等仓库通信,确保镜像正确下载和构建。
1593 59
|
8月前
|
Java Docker 容器
使用Docker多阶段构建优化镜像大小
使用Docker多阶段构建优化镜像大小
359 8
|
9月前
|
缓存 Ubuntu Docker
Ubuntu环境下删除Docker镜像与容器、配置静态IP地址教程。
如果遇见问题或者想回滚改动, 可以重启系统.
590 16
|
缓存 Shell 网络安全
将应用程序打包成Docker镜像时可能遇到哪些问题?
将应用程序打包成Docker镜像时可能遇到哪些问题?
1113 77

热门文章

最新文章