33

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.

Dockerfile content

#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"

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

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

Question 3 : Is the final image formed with multiple layers saved from intermediate containers?

4

1 回答 1

48

是的,Docker 镜像是分层的。当您构建新映像时,Docker 会为Dockerfile 中的每条指令(等)RUN执行此操作:COPY

  1. 从前一个镜像层(或FROM第一个命令的基础镜像)创建一个临时容器;
  2. 在临时“中间”容器中运行 Dockerfile 指令;
  3. 将临时容器保存为新的图像层。

最终的图像层被标记为您命名图像的任何名称 - 如果您运行这将很清楚docker history raghavendar/hands-on:2.0,您将看到每个层以及创建它的指令的缩写。

您的具体查询:

1)532是从图像 ID 创建的临时容器b17,这是您的FROM图像,ubuntu:14.04.

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

3) 是的。Docker 将其称为联合文件系统,这也是镜像如此高效的主要原因。

于 2016-09-26T15:34:10.833 回答