Docker Containers and Images

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 :

  • You created a file with everything that you need to cook, spices, groceries etc including appliances and power supply
  • You shared the file with a local food truck manufacturer.
  • He took the file, and prepared the designs for you.
  • Thereafter, he created the truck out of that design.
  • You took the truck everywhere and everything went smoothly
  • Soon, you became so popular that you get invites for multiple events
  • You ordered, multiple food trucks
  • The manufacturer, using the same design create your trucks
  • You maintained the same quality, and business thrived

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

  • Dockerfile : Specification of our app requirements and the environment setup it needs
  • Images : Created from the dockerfile, these are blueprints for containers. We can create as many containers as we need from an image
  • Container : The stand-alone and isolated unit that has all the environment setup that our application needs to run


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

要查看或添加评论,请登录

Danish Javed的更多文章

  • Spring Boot and Node Applications in Docker

    Spring Boot and Node Applications in Docker

    Now we are finally getting close to a production setup. In microservices we have multiple instance of multiple…

  • Docker Setup

    Docker Setup

    Finally we are going to setup and run our first container. Excited ?! Alright, lets begin.

  • Docker Perquisite understanding & Setup

    Docker Perquisite understanding & Setup

    This is continuation of my previous article. if you haven't read that already, I recommend reading that first :…

  • Docker Overview

    Docker Overview

    Before diving in with what is Docker, we first need to understand why is docker and what problem it is trying to solve…

社区洞察

其他会员也浏览了