Docker Day 2: Mastering the Container Lifecycle

RachanaRachana
4 min read

In the previous blog, I have discussed the fundamental concept of Containerization and problems solved by it. What you need to know thoroughly by now is that, Containerization is a technology and Docker is the platform that implements Containerization.

Now, its time to understand the Lifecycle of Docker. In this blog, we will discuss all the important Docker terms like images, containers, daemon etc in detail.

Docker Lifecycle:

Imagine you are preparing and selling your own brand of cup noodles. It's your own recipe, so you have it written on a piece of paper. This paper lists all the ingredients you need and the steps you must follow to prepare the cup noodles. Following the recipe, you package all the ingredients in small cups. Now, you want consumers to buy your cup noodles, so you distribute the cups to convenience stores. People purchase your cups, and all they need to do is add hot water to enjoy the cup noodles you made.

This is exactly how the Docker Lifecycle works.

  1. The piece of paper containing your recipe is the Dockerfile. It consists of the instructions to build your Docker Image.

  2. The packaging of your ingredients into cups as mentioned in the recipe is the building of Docker Images from Dockerfile(recipe). The command used to build Docker Images from Docker file is docker build

  3. Now, you can cook the noodles by just adding water to the cups and consume it. This is bringing your Docker Images to life to run the Docker Containers, using the command docker run

  4. Distributing your cups to convenience stores is pushing your Docker Images to Registries, for others to utilize. Docker Images can be pushed using the command docker push

What is Docker? - GeeksforGeeks

Now, lets try to understand this image:

  1. All the docker commands to run, build and push are sent to the docker daemon from the docker client.

  2. When the command is docker build, the daemon refers to the Dockerfile and creates the Docker Image.

  3. When the command is docker run, the daemon executes the Docker Image to run a Docker Container.

  4. When the command is docker push, the daemon pushes the particular image and registry. And pulls an image from the repository when the command is docker pull.

What did we understand from this?

Every operation like creation, running and pushing of containers and images are performed by the Docker Daemon, making it the single point of failure. If the Docker Daemon goes down, all its images and container go down, which is one of the disadvantages of Docker.

Docker terms you need to know:

  1. Docker Images - It is a blueprint of the dependencies and libraries required for the application in a container to run. It is used to build Docker containers.

  2. Docker Containers - It is a lightweight, self-sufficient, executable package consisting of everything required for the application to run i.e., everything specified in the Docker Image it was created from. It can run in any environment.

  3. Dockerfile - It is the file specifying the steps to build the Docker Image and include the necessary dependencies.

  4. Docker Client - It is the primary way for the client to interact with Docker, using commands like 'docker run'

  5. Docker Registry - It is a place to store Docker Images. You can pull and push Docker images from registries. One of the most common examples are Docker Hub, Quay.io etc. The registries can either be public or private.

  6. Docker Daemon - It is the service responsible for orchestrating container lifecycle management i.e., it handles various tasks like container creation, execution and monitoring. It acts as a bridge between Docker Client and the Registry.

In this blog, we delved into the lifecycle of Docker, exploring the essential components and processes that make containerization possible. As we continue to explore Docker, this foundational knowledge will serve as a stepping stone to more advanced topics and practical applications in the world of containerization.

1
Subscribe to my newsletter

Read articles from Rachana directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rachana
Rachana

Hi to the fellow tech enthusiasts out there! πŸ‘‹ I am an aspiring Cloud and DevOps Engineer ☁️ With strong foundation in containerization technologies like Docker and Kubernetes🐳 Capable of building resilient, secure and cost optimized infrastructure on AWS cloud - AWS SAA certified.β˜οΈπŸ”’ Currently learning to build CI/CD pipelines using Jenkins, github-actions, AWS CodePipeline, and many more.πŸ› οΈπŸ”„ Exploring other tools like Ansible for configuration management and Terraform for Infrastructure as Code(IaC).πŸ§©πŸ“œ Let's connect, learn and grow together! 🌟🀝