Docker:如何形成中间容器 [英] Docker : How are intermediate containers formed

查看:283
本文介绍了Docker:如何形成中间容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解使用Dockerfile构建Docker Images的执行步骤。我下面列出的几个问题。请帮助我了解构建过程。

I would like to understand the execution steps involved in building Docker Images using Dockerfile. Couple of questions I have listed down below. Please help me in understanding the build process.

#from base image
FROM ubuntu:14.04
#author name
MAINTAINER RAGHU
#commands to run in the container
RUN echo "hello Raghu"
RUN sleep 10
RUN echo "TASK COMPLETED"

用于构建映像的命令: code> docker build -t raghavendar / hands-on:2.0。

Command used to build the image: docker build -t raghavendar/hands-on:2.0 .

Sending build context to Docker daemon 20.04 MB
Step 1 : FROM ubuntu:14.04
---> b1719e1db756
Step 2 : MAINTAINER RAGHU
---> Running in 532ed79e6d55
---> ea6184bb8ef5
Removing intermediate container 532ed79e6d55
Step 3 : RUN echo "hello Raghu"
---> Running in da327c9b871a
hello Raghu
---> f02ff92252e2
Removing intermediate container da327c9b871a
Step 4 : RUN sleep 10
---> Running in aa58dea59595
---> fe9e9648e969
Removing intermediate container aa58dea59595
Step 5 : RUN echo "TASK COMPLETED"
---> Running in 612adda45c52
TASK COMPLETED
---> 86c73954ea96
Removing intermediate container 612adda45c52
Successfully built 86c73954ea96

在步骤2中:
步骤2:MAINTAINER RAGHU
--->在532ed79e6d55中运行[问题1:它表示它正在容器中运行,ID为 - 532ed79e6d55,但是这个容器是否形成了Docker映像? ]

---> ea6184bb8ef5 [问题2:这个id是什么?是否是图像或容器?]
删除中间容器532ed79e6d55

In step 2 : Step 2 : MAINTAINER RAGHU ---> Running in 532ed79e6d55 [ Question 1 : it indicates that it is running in the container with id - 532ed79e6d55, but with what Docker image is this container formed ? ]
---> ea6184bb8ef5 [ Question 2 : what is this id? Is it an image or container ?] Removing intermediate container 532ed79e6d55

问题3:最终图像是否在不同图层上形成多个容器?<​​/ p>

Question 3 : Is the final image formed with multiple containers at different layers?

推荐答案

是的,Docker图像是分层的。当您构建新映像时,Docker对您的Dockerfile中的每个指令( RUN COPY 等)执行此操作。

Yes, Docker images are layered. When you build a new image, Docker does this for each instruction (RUN, COPY etc.) in your Dockerfile:


  1. 从上一个图层(或基础 FROM 图像创建一个临时容器对于第一个命令;

  2. 在临时中间容器中运行Dockerfile指令;

  3. 将临时容器保存为新的图像层。 / li>
  1. create a temporary container from the previous image layer (or the base FROM image for the first command;
  2. run the Dockerfile instruction in the temporary "intermediate" container;
  3. save the temporary container as a new image layer.

最终图像层被标记为您命名的图像 - 如果您运行 docker历史记录,这将是清楚的raghavendar / hand-on:2.0 ,您将看到每个图层和创建它的说明的缩写。

The final image layer is tagged with whatever you name the image - this will be clear if you run docker history raghavendar/hands-on:2.0, you'll see each layer and an abbreviation of the instruction that created it.

您的具体查询:

1) 532 是从图像ID b17 ,这是您的 FROM image, ubuntu:14.04

1) 532 is a temporary container created from image ID b17, which is your FROM image, ubuntu:14.04.

2) ea6 是作为指令输出创建的图像层,即从保存中间容器 532

2) ea6 is the image layer created as the output of the instruction, i.e. from saving intermediate container 532.

3)是的。 Docker称之为联合档案系统,它是主要的图像如此高效的原因。

3) yes. Docker calls this the Union File System and it's the main reason why images are so efficient.

这篇关于Docker:如何形成中间容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆