• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > 最小 Docker 镜像 hello-world 剖析,dockerhello-world

最小 Docker 镜像 hello-world 剖析,dockerhello-world

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含docker镜像,docker镜像仓库,docker镜像下载,阿里云docker镜像,docker 镜像制作等服务器相关知识,网友希望可以进行参考

最小 Docker 镜像 hello-world 剖析,dockerhello-world


开始学习 Docker 的同学基本上都是按照官方的 guide 来安装,之后要测试是否已经安装成功,官方会让你 pull 一个 hello-world 示例镜像下来并运行,如下命令:

 guohl@ghl-MBP ? ~ ? docker pull hello-world
31cbccb51277: Pull complete
e45a5af57b00: Pull complete
511136ea3c5a: Already exists
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Status: Downloaded newer image for hello-world:latest

guohl@ghl-MBP ? ~ ? docker run hello-world
Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (Assuming it was not already locally available.)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

For more examples and ideas, visit:
 http://docs.docker.com/userguide/

出现上面的输出信息表示你 Docker 安装成功。使用下面命令查看该镜像的信息,发现大小只有 910B:

guohl@ghl-MBP ? ~ ? docker images hello-world
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
hello-world         latest              e45a5af57b00        3 months ago        910 B

那么该镜像运行怎么就输出上面这一串信息的呢?如果对 Docker 了解一点的话自然会去找该镜像的 Dockerfile,Dockerfile 详细描述了该镜像是如何建立的以及运行时执行的命令。从 Docker Hub 上 hello-world 的库简介 找到其 Dockerfile 在 github 上,简简单单的三条语句:

FROM scratch
ADD hello /
CMD ["/hello"]
  • 第一条FROM指令是 Docker 用来指定该镜像是基于哪个基础镜像构建的,这里指定为 scratch,实际上 scratch 镜像是一个空镜像,用来构建基础镜像或者极小的镜像。
  • 第二条ADD指令表示从 Dockerfile 所在目录拷贝文件到指定路径下,这里拷贝 hello 文件到根目录下,至于 hello 文件是什么稍后介绍。
  • 第三条CMD指令用来指示当运行 docker run 命令运行该镜像时要执行的命令,这里执行 /hello,就是执行第二步拷贝到根目录下的 hello 文件。

hello 是一个可执行的二进制文件,从文章的开头可以推测该文件执行输出那一堆提示信息,那该文件怎样生成的呢?从 hello-world 的库中可以看到还有两个文件,一个是汇编文件 hello.asm,还有一个 Makefile 文件,可以猜测 hello 就是事先通过 hello.asm 编译得到的,如 Makefile 文件所描述的编译过程:

hello: hello.asm
    nasm -o $@ $<
    chmod +x hello

.PHONY: clean
clean:
    -rm -vf hello

该 Makefile 文件比较容易理解,主要是使用 nasm 汇编器将 hello.asm 编译生成可执行文件 hello。

最后再来看看 hello.asm 文件,这是一段 Intel x86 汇编:

; this is especially thanks to:
; http://blog.markloiseau.com/2012/05/tiny-64-bit-elf-executables/

BITS 64
    org 0x00400000  ; Program load offset

; 64-bit ELF header
ehdr:
    ;  1), 0 (ABI ver.)
    db 0x7F, "ELF", 2, 1, 1, 0       ; e_ident
    times 8 db 0                     ; reserved (zeroes)

    dw 2              ; e_type: Executable file
    dw 0x3e           ; e_machine:  AMD64
    dd 1              ; e_version:  current version
    dq _start         ; e_entry:    program entry address (0x78)
    dq phdr - $$      ; e_phoff   program header offset (0x40)
    dq 0              ; e_shoff no section headers
    dd 0              ; e_flags no flags
    dw ehdrsize       ; e_ehsize:   ELF header size (0x40)
    dw phdrsize       ; e_phentsize:    program header size (0x38)
    dw 1              ; e_phnum:    one program header
    dw 0              ; e_shentsize
    dw 0              ; e_shnum
    dw 0              ; e_shstrndx

ehdrsize equ $ - ehdr

; 64-bit ELF program header
phdr:
    dd 1              ; p_type: loadable segment
    dd 5              ; p_flags read and execute
    dq 0              ; p_off
  


 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Docker 使用方法总结之:镜像,docker总结
  • 搭建私有 Docker 仓库服务器,docker仓库
  • 最小 Docker 镜像 hello-world 剖析,dockerhello-world

相关文章

  • AWS EC2 调整云主机根卷大小,awsec2
  • Cloud Foundry service broker开发部署实例解析(下),foundrybroker
  • [Spark源码剖析] DAGScheduler划分stage,sparkdagscheduler
  • 《3》CentOS7.0+OpenStack+kvm云平台部署—配置Glance,《3》kvm
  • jstl fn:substring()函数代码和用法,jstlsubstring
  • MongoDB 安装与启动,MongoDB安装启动
  • Spark 基于item和user 的协同过滤实现,sparkitem
  • Xen安全架构sHype/ACM和XSM/Flask的相关网络资源,xenshype
  • Linux系统只能连上内网不能够连上外网。Unit network.service entered failed state.,外网访问内网服务器
  • redis学习笔记之pipeline,redispipeline

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • hbase遇到问题及解决方法,hbase遇到问题
    • 云主机跟VPS哪个比较好?哪个稳定安全?,主机vps
    • 常见类型网站的SEO应该怎么操作?类型不同,操作自然不同,因为分门别类嘛,seo分门别类
    • 机器学习-Python中训练模型的保存和再使用,-python模型
    • hive FAILED: ParseException line 1:814 cannot recognize input near ‘;’ &lt;EOF&gt;’,hiveparseexception
    • 创建GZIP压缩格式的HIVE表,gzip压缩格式hive
    • 家,我日夜思念的名字,我回来了,
    • Docker安装MySQL8.0的实现方法
    • 一步一步跟我学习hadoop(4)----hadoop Map/Reduce教程(1),hadoop----hadoop
    • [Hive]关于Hive的启动问题,hive启动问题

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有