Docker Containers and Images
This is continuation of my previous article. if you haven't read that already, I recommend reading that first : https://www.dhirubhai.net/pulse/docker-overview-danish-javed-zpazf/
In the previous article I tried explaining an overview of docker. Let's build on top of that and understand about images and containers.
A fun example
Let's assume you are a small home-chef. One day you are hosting a house party. Your colleagues and friends, everyone is there. One of your colleagues loved the food so much that he asked you to cater for his son's birthday next week. You agreed.
When you arrived at his home and just started cooking immediately, you noticed that his place did not have a food processor. In the absence of it, you can't make the dosa everyone loved last time.
In the next party, you took your food processor with you but this time they did not had a compatible socket. Again you could not make that dosa.
You decided to fix this with a small food truck. Here are the steps :
That's entire docker summed up for us. Let me explain
Docker references from the example
Container
The food truck, provided you an environment in which you had everything you needed to work. That is the thing where you cook and do the actual work
Similarly, in docker, we have container. Just like actual cooking happens inside the food truck, here our application runs inside a container.
Think of containers as lightweight, isolated environments for running applications. They package everything needed for our app like code, dependencies, and configurations. For understanding, you can think of them as tiny little VMs but of course they don't have a kernel of their own. They share the host OS kernel instead of running a full OS like a VM.
领英推荐
Images
The design that the manufacturer created, using which he created n number of food trucks later on, is docker image.
Think of docker images, as class and containers as objects. Like classes are blueprint of objects, images are blueprints of containers. We can create n number of objects of a class. Similarly, we can create n numbers of containers from images.
Docker file
Remember the file you created with all you requirements ? The file based on which the manufacturer created his designs. That, in docker terms, is dockerfile
Like I mentioned that containers have everything your application needs to run, and that images are blueprint of the containers, so image should must have the details about all our application's requirement. But how will it get to know all of that ? How will it know what OS and apps and environment variables we need ?
In dockerfile, we tell our application's requirements. Like what OS we need, what all software are required for our app to run etc.
To conclude
Your requirement file = dockerfile
Manufacturer designs = docker image
Food truck = docker container
In the next article, we'll setup our (windows) system to be able to run docker. We'll understand a little about VMs and hopefully run first container.
Since I get time to draft these only on the weekends, you can checkout my notes at technotes.devdanish.in/docker