Docker Containers — Learn DevOps Concept like I’m five

Shikhar Srivastava
6 min readFeb 24, 2021

Last Article in this series https://shikhar-sri2.medium.com/vm-vs-docker-learn-devops-concepts-like-i-am-five-series-4a4b2282b7e4

Before start, let me familiarize you with our characters, an earnest boy named Russel who is a newbie in the DevOps world, and our elderly experienced guy in this domain Carl Fredricksen.

Carl : (Thinking Loud) Today’s morning is so calm and quiet. It's the weekend also, a great combination. Will rest the whole day after a long time.

Russ: Hey Carl! I am here :) (Russ shouted in excitement)

Carl: Not now, please. Today is my rest day.

Russ: No it will take some time only and you have the whole day to rest.

Carl: Hmm .. now I don't think so. 😛 Okay, let's start.

Russ: I want to learn more about Docker, but everywhere I find too many technical words. Why everyone explains it in such a complicated way.

Carl: The explanation is not complicated, you just don’t have a background. Let me explain to you with an example of our hero ‘Mickey’.

Mickey is a Sales Manager and has a Transferable job. Due to his company requirements, he needs to move to several places in a year. This transfer comes with the overhead of moving his home luggage too as he has several members in his family (Minnie (Wife), Goofy (Son)) considering that they are very particular about their stuff.

Each time the whole family moves to a different place, somethings get missed or new stuff they buy doesn’t match with the old thing they carried over. This creates a mess and mostly results in disputes.

To solve this once Mickey got an idea. Let's see their conversation

Mickey: Hey all, before moving to a new place this time, let's prepare a detailed list of items we need for our rooms with each detail like you Goofy, you always create an issue with the size and dimensions of the table, your toys, etc.

You all prepare a list of items of your items in your room, you all need to make you feel at home and I will prepare one more list of common items we all require, as its necessity as a whole. This list will have instructions also to set up for a new home, we can call it a master list.

Minnie, Goofy: But why? We know all the things.

Mickey: DO AS I SAID.

Mickey has all the list now.

The Day comes when they need to shift to a new place and environment.

Mickey: Minnie, Goofy give that list of items and doesn’t pack anything. We will go empty-handed. I already sold all stuff.

Minnie: What! What’s your plan.

Mickey: I am going to give this to my manager at our new place. He is going to buy all items with the version and details you listed and make the place ready for us before we reach there.

Minnie: Wow that's great, this way we can save money by shifting and carrying all house items. Also, we are not occupying any space and saving rent.

Mickey: Ya that’s correct.

Russ: I really liked the story. But why are you telling me this, I asked you about Dockers.

Carl: Hahaha! Yes, I am glad you didn’t get lost.

This is very much related to Docker.

In your case, you have different needs for your applications which works fine together with particular versions of those. Also, you have some basic needs like OS with some particular configuration like Java/Maven or NodeJS setup.

Comparing with the above scenario of Mickey, this was the same situation. Mickey, Minnie, and Goofy wanted their items to be present and some necessary stuff common to all. For that, they created a master list.

In Docker, the term that lists each self-contained app needs is a Dockerfile.

DockerFile

Dockerfile is a blueprint of all the dependencies and other configurations require for a self-contained app to run.

Here is a sample docker file

FROM nginx:latest
MAINTAINER NAME EMAIL

RUN apt-get -y update && apt-get -y upgrade && apt-get install -y php-fpm

Based on this blueprint, we can download all dependencies, environment configurations, and even the source code with a simple command docker build

docker build

We called then the ready self-contained app as Docker image.

Dockerfiles are simple text files that contain the commands to assemble an image that will be used to deploy containers.

Russ: Great! then how do we run them?

Carl: Using another simple command

docker run

So now we have each individual's room ready for Mickey’s family or you can say your modules are ready to function inside each Docker Container.

Russ: But what about telling the Manager how to set up each individual’s room concerning others. Maybe he will misplace Kitchen with Goofy’s room or Mickey’s with Goofy’s room. Like how they need to be placed.

Carl: Hahaha, correct. You remember Mickey prepared another mater list to tell all these. That you can compare as the docker-compose.yml file

docker-compose.yml files are used for defining and running multi-container Docker applications using a simple command

docker-compose up

Russ: Wow! so that’s the whole flow.

Carl: Yes

So the workflow looks like this:

  1. Create Dockerfiles to build images.
  2. Define complex stacks (comprising of individual containers) based on those Dockerfile images from within docker-compose.yml.
  3. Deploy the entire stack with the docker-compose command.

Russ: Great! So it will even solve my problem of using my application in a different env or even if some other developers wish to set it up on his system. I can just pass the Dockerfile and he can build the whole system just with simple commands.

Carl: You got it so well!

Russ: But Mickey has prepared the list so well. Many guys in his team will be having the same transferable job, why won't he share that list with them. By this, anyone can just use that to set up their homes and maybe customize something on that.

Similar in the case of Docker images. Suppose I have created an image, an environment to run the NodeJS application, then why my teammate again needs to create the same. Let's share.

Carl: Yes, you asked the right question and fortunately creators of docker have already solved it. We have an online Repository hosted by Docker Team called Docker Hub where anyone can upload images and others can just download and use them. They can even use that as a base image and customize it on top of that.

Docker Hub

Docker Hub is a service provided by Docker for finding and sharing container images with your team. It is the world’s largest repository of container images with an array of content sources including container community developers, open-source projects, and independent software vendors (ISV) building and distributing their code in containers.

Russ: That seems Docker has a solution to all my problems 😃

Russ: I have another question. I have the app ready now which I can run in any env but how to specify how much space I need on the server, what if my docker image crashed, what if I want to scale it up based on my increasing user needs, what if I want to run different versions of applications parallel, what if ….

Carl: Too much what if … Take this as your next homework and let's meet another day. As a hint, explore Kubernetes.

Russ: Aiyee Sir!!

--

--

Shikhar Srivastava

SRE / DevOps Engineer with rich experience in multiple renowned firms. I am here to give back to the community by sharing knowledge!!