Docker Image vs Container


Understanding the process Docker uses to store data through images and containers will help you better design your Docker applications. Docker images are like templates while Docker containers are the running instances created from those templates. Docker uses a layered approach to storing images and containers.

Images and Layers

A Docker image is created from multiple layers. If we take an example of a Dockerfile, every instruction is converted to a layer. Here is a simple Dockerfile:

  FROM node:6.9.2  COPY server.js .  CMD node server.js  

Every line in the above Dockerfile will create a layer. The FROM statement will look for the node:6.9.2 image in the local registry. If it doesn’t find it there, then it will download it from the Docker Hub. Then Docker will create the first layer. The next COPY statement adds the server.js file to the image as a second layer. The last layer runs a Node.js application. All these layers are stacked on top of each other. Each additional layer is added as a difference from the layer before it.

Containers and Layers

Containers are created from images. When a container is created from an image, a thin read/write layer is put on top of the image (Notice that image layers are immutable, container layers are not). Any changes made to the container is put on this read/write layer during the lifetime of the container. When a container is deleted, the associated thin read/write layer is removed. It means that multiple containers can share the same image. Each container layer will maintain its own data safely on top of the Docker image.

Images and Containers

Let’s try a simple example.  You can use the docker images command to find all the images:

  $ docker images    REPOSITORY          TAG      IMAGE ID      CREATED      SIZE  

And the docker ps command to find containers:


This is a fresh docker installation. So there is no image or container present. You can run the docker run -it node:6.9.2 command to start a container.

  $ docker run -it node:6.9.2  Unable to find image 'node:6.9.2' locally  6.9.2: Pulling from library/node    75a822cd7888: Pull complete   57de64c72267: Pull complete   4306be1e8943: Pull complete   871436ab7225: Pull complete   0110c26a367a: Pull complete   1f04fe713f1b: Pull complete   ac7c0b5fb553: Pull complete   Digest: sha256:2e95be60faf429d6c97d928c762cb36f1940f4456ce4bd33fbdc34de94a5e043  Status: Downloaded newer image for node:6.9.2  >  

Now if we again check the Docker images, we find:

  $ docker images    REPOSITORY      TAG         IMAGE ID         CREATED           SIZE  node           6.9.2      faaadb4aaf9b     11 months ago       655MB  

And if we check container, we find:

  $ docker ps    CONTAINER ID    IMAGE   COMMAND CREATED        STATUS      PORTS  NAMES  8c48c7e03bc7 node:6.9.2 "node" 20 seconds ago Up 18 seconds     reverent_jackson  

If we start another container from the same image using the command:

  $ docker run -it node:6.9.2  

And check again, we see:

  $ docker images    REPOSITORY      TAG         IMAGE ID      CREATED            SIZE  node           6.9.2      faaadb4aaf9b  11 months ago       655MB  


  $ docker ps    CONTAINER ID    IMAGE    COMMAND CREATED        STATUS        PORTS NAMES  96e6db955276  node:6.9.2 "node"  24 seconds ago Up 23 seconds    cocky_dijkstra  8c48c7e03bc7  node:6.9.2 "node"  4 minutes ago  Up 4 minutes     reverent_jackson  

The two containers with CONTAINER ID 96e6db955276 and 8c48c7e03bc7 are both running on top of the Docker image with the IMAGE ID faaadb4aaf9b. The thin read/write layers of the Docker containers are residing on top of the layer of the Docker image.


You can remove Docker containers with the command docker rm [CONTAINER ID] and remove Docker images with the command docker rmi [IMAGE ID].

The image node:6.9.2 we downloaded from Docker Hub is also created by combining multiple layers. You can check the layers of images using docker history [IMAGE ID].

  $ docker history faaadb4aaf9b    IMAGE        CREATED         CREATED BY                            SIZE     faaadb4aaf9b 11 months ago /bin/sh -c #(nop)  CMD ["node"]          0B                    <missing> 11 months ago /bin/sh -c curl -SLO " 42.5MB                <missing> 11 months ago /bin/sh -c #(nop)  ENV NODE_VERSION=6.9.2  0B                    <missing> 11 months ago /bin/sh -c #(nop)  ENV NPM_CONFIG_LOGLEVEL 0B                    <missing> 11 months ago /bin/sh -c set -ex   && for key in     955 108kB                 <missing> 11 months ago /bin/sh -c groupadd --gid 1000 node   && u 335kB                 <missing> 11 months ago /bin/sh -c apt-get update && apt-get insta 323MB                 


A popular way of explaining images and containers is to compare an image to a class and a container to the instance of that class. The layered approach of docker images and containers helps keep the size of images and containers small.


ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

A Beginner’s Guide To Docker Compose

Docker Compose is one of the most useful tools for Software Developers and System Administrators. Many jobs require someone...

Docker Overlay Driver and Overlay Networking

Docker comes with three networking drivers by default. Network adapters are also initialized using these drivers, carrying...

How to Install Docker on Linux Mint

In the professional world, there are a number of a really, really powerful tools that are powering the back-end of today’s...
Bài Viết

Bài Viết Mới Cập Nhật

Check proxy trên trang nào chuẩn nhất❓

Thuê Proxy chạy Google Ads / Cần chú ý gì khi chọn proxy và email chạy G.G ads?

Thuê proxy 4G ở đâu uy tín, giá rẻ, chất lượng?

Vì sao cần thuê proxy xoay? Địa chỉ cung cấp proxy xoay uy tín

Thuê proxy v6 kéo view Youtube ở đâu uy tín, chất lượng?