Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are intermediate containers formed?

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?

like image 209
Here_2_learn Avatar asked Sep 26 '16 14:09

Here_2_learn


People also ask

What is intermediate container?

Intermediate bulk containers (also known as IBC tank, IBC tote, IBC, or pallet tank) are industrial-grade containers engineered for the mass handling, transport, and storage of liquids, semi-solids, pastes, or solids.

How do internal containers work?

Docker uses the union file system to create and layer Docker images. This means all images are built on top of a base image, actions are then added to that base image. For example, RUN apt install curl creates a new image.

What is the life cycle of a container?

The complete lifecycle of a docker container revolves around five phases: Create phase. Running phase. Paused phase/unpause phase.


1 Answers

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

  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.

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.

Your specific queries:

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

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

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

like image 85
Elton Stoneman Avatar answered Sep 25 '22 17:09

Elton Stoneman