zoukankan      html  css  js  c++  java
  • 容器技术(三)最小的镜像【4】

    (一)最小的镜像

    镜像是 Docker 容器的基石,容器是镜像的运行实例,有了镜像才能启动容器。

    (1)镜像的内部结构

    ​ 为什么我们要讨论镜像的内部结构?如果只是使用镜像,当然不需要了解,直接通过 docker 命令下载和运行就可以了。但如果我们想创建自己的镜像,或者想理解 Docker 为什么是轻量级的,就非常有必要学习这部分知识了。

    (2)hello-word最小的镜像

    ​ hello-world 是 Docker 官方提供的一个镜像,通常用来验证 Docker 是否安装成功。我们先通过 docker pull 从 Docker Hub 下载它。

    root@cuiyongchao:~# docker pull hello-world
    Using default tag: latest
    latest: Pulling from library/hello-world
    0e03bdcc26d7: Already exists 
    Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
    Status: Downloaded newer image for hello-world:latest
    docker.io/library/hello-world:latest
    root@cuiyongchao:~# 
    

    ​ 通过docker images 命令查看镜像详细信息:

    root@cuiyongchao:~# docker images hello-world
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    hello-world         latest              bf756fb1ae65        9 months ago        13.3kB
    root@cuiyongchao:~#
    

    ​ 使用docker run运行容器:

    root@cuiyongchao:~# docker run  hello-world
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    

    ​ 其实我们更关心 hello-world 镜像包含哪些内容。

    ​ Dockerfile 是镜像的描述文件,定义了如何构建 Docker 镜像。Dockerfile 的语法简洁且可读性强,后面我们会专门讨论如何编写 Dockerfile。hello-world 的 Dockerfile 内容如下:

    FROM scratch
    COPY hello /
    CMD ["/hello"]
    
    • FROM scratch,此镜像是从白手起家,从 0 开始构建。

    • COPY hello /,将文件“hello”复制到镜像的根目录。

    • CMD ["/hello"],容器启动时,执行 /hello

      镜像 hello-world 中就只有一个可执行文件 “hello”,其功能就是打印出 “Hello from Docker ......” 等信息。 /hello 就是文件系统的全部内容,连最基本的 /bin,/usr, /lib, /dev 都没有。hello-world 虽然是一个完整的镜像,但它并没有什么实际用途。通常来说,我们希望镜像能提供一个基本的操作系统环境,用户可以根据需要安装和配置软件。这样的镜像我们称作 base 镜像。

  • 相关阅读:
    Eclipse快速上手指南之使用CVS
    数据备份的13种最佳做法
    用asp.net来回收IIS6.0应用程序池
    构建插件式的应用程序框架(五)-管理插件
    安全组织评出25个最危险软件编程错误
    在ASP.NET里轻松实现缩略图
    构建插件式的应用程序框架(六)-通讯机制
    快照复制,SQL Server保障数据一致性的法宝
    DataGridView新特色、常用操作
    如何在GridView中一次性批量更新多行数据
  • 原文地址:https://www.cnblogs.com/cuiyongchao007/p/13899055.html
Copyright © 2011-2022 走看看