Updated: Sep 11, 2021
Docker is a de-facto standard in containerization technology. But before containers come to life there is something more needed to bring them to life. This is Docker images. Today, in this blog I am going to discuss Docker images, which is behind the Docker containers.
What are Docker images ?
A Docker image is a binary file. It contains a minimal runtime of an Operating System Kernel, OS libraries, other tools and dependent packages to run application(s) and executables of applications that need to be bundled within the image. The minimum that is required to execute code when a Docker container will be creed from the Docker Image. An Image also contains metadata that describes its capabilities. Images are basic building blocks in Docker. Docker containers are created from Images. A Docker container is a living thing where Image is a skeleton. An image can be saved for later to create containers. Images can be uploaded to a library called Docker Registry.
What are Image Layers?
A Docker Image is made with multiple layers. There is always a base layer that contains the minimum OS Kernel runtime. We run a container from the base image and install packages and software or do any modification on the container and stop the execution of the container. The changes made in the container are saved in the stopped container. You can again start the container and do another change. We can create an Image from the stopped containers. This is the principle used to create layers of Image. We can use this Image as a parent image and add something more to it and create another image. The base images for all Linux versions are already provided to us by Docker so we don't have to create them on our own. For example, if you can use a base image of Ubuntu and create another image with Nginx application in it. An Official version of the off--the-shelf software is also available in Docker registry. The registry is called Docker hub.
How Docker Images are created?
A Docker Image can be created using the interactive method explained in the previous paragraph above. A better method is using a file.
All the commands needed to create a new image from the base image can be saved into a text file. Then the Image can be created from this file. This is called Dockerfile. Each instruction written in the docker file is taken one by one by Docker engine from top to bottom and a layer is added for each of them. These layers are read only layers except the topmost layer. The top most layer of an Image is a container and it is writable. We can use the docker build command to create an Image from the dockerfile. The first statement in the Dockerfile is the From statement that instructs what is the parent Image for the Docker Image that we want to build. An example of a dockerfile as as below.
FROM ubuntu:17.04 COPY ./appFolder RUN make /appFile CMD python /appFile/app.py
Docker uses a Copy-on-write union file system to store images. When we make any change to a container, only the changes are written to disk using the copy on write model.
Below is a list of statements that can be used in the Dockerfile.
This Docker documentation explains how to create a Docker image.
How Docker Images are used?
A Docker Image can be used to create another Docker Image. A Docker Image is used to create and run Docker containers.