The Power of Docker Containers

Bennison J
YavarTechWorks
Published in
6 min readMay 28, 2024
The Power of Docker Containers

In this article we will learn about VM (Virtual Machine), what docker is, and why docker is.

Before moving on to the topic of Docker Container, I would like to explain what it replaces, it replaces the VMs(Virtual Machines)

What is Virtual Machins (VMs)

  • Traditionally, before the virtual machine, we could install an operating system in hardware (server hardware). and all of the CPU, RAM, and disk are only dedicated to that single operating system. You may ask a question like “What is the problem with that”. There is no problem unless you want another server.
  • But before virtual machines, if you wanted to have a Linux server and another Windows server, you had to have two physical servers. So that’s where the virtualization comes in, Here instead of installing one operating system, we are going to install something called hyperviser.

What is HypherViser?

  • Hypervisors are like operating systems, but they have only one goal. its goal is to divide your server’s resources into multiple servers.
  • There are a lot of hypervisors available, but the most popular one is VMware.
  • It allows us to take a portion of a server's resources to run any operating system such as Ubuntu, and Windows inside an operating system.
  • We can create multiple Virtual Machines inside a server until our server runs out of the resources.
  • When we use the docker container, we will use only one operating system in the server.
  • Here you may ask a question like “What exactly is Docker doing here”, and the answer is that virtual machine and virtualization are virtualizing the hardware, and Docker Virtualizes the Operating System.
Diff between VMs and Docker Container

What are Containers?

  • Containers are like fast lightweight microcomputers. here in a docker container, each virtual machine has its own Operating System (OS), CPU process, memory, and network. and Each operating system, CPU, memory, and network is individually isolated within its virtual machine.

Docker Installations

for demonstration purposes, I will install CentOS using Docker on my Linux machine.

To install this thing we need images, So I am going to pull the docker images from the docker hub

sudo docker pull centos

The above command pulls the image (here centos) from the docker hub which is the registry of docker images. these images are what we use to run or create our containers.

Once we pull the centos from the docker registry, with the centos image we are going to run our first container

sudo docker run -d -t --name <name of the container> centos

Explanation of the above command

  1. docker run: This is the command to create and start a new Docker container.
  2. -d: This option runs the container in detached mode, meaning the container runs in the background and the terminal is not attached to the container’s output.
  3. -t: This is useful for interactive processes or when interacting with the container’s terminal.
  4. --name <name of the container>: This option assigns a name to the container.
  5. centos: This specifies the image to use for the container. In this case, it uses the official CentOS image from Docker Hub.

When we compare this booting setup with the virtual machine it is super fast. booting a virtual machine takes more time.

Listing running docker container

By providing the below command we could see all the running docker containers.

sudo docker ps
running docker images as a container

Now, this command will show the running docker container centos.

Now this centos is isolated and secure, running with its own operating system, CPU, memory, and network.

We can connect to this CentOS from our Linux machine using the command below.

sudo docker exec -it <name of the container> bash

Once we run the below command, we will be logged into our container shell (In our case it is CentOS). By running the command exit we can back our Linux machine.

Loggin to Container’s Shell

Now in the above snap, we can see that I have logged into my container (CentOS) shell using the command docker exec . in the above snap, we can see that the container (CentOS) has its own file system.

Here you may ask a question like “Do we need to configure anything(here in our example CentOS)?”

The answer is, that we don’t need to set any other things, but if we pull down the images and run that as a container as I explained above, we have an operating system installed (In our case it is OS, but in some case, it could be any service that runs in an OS). In docker, all these configurations including OS, CPU, memory, all the pre-requests, and dependencies are packaged together in a neat little package as a container. We don't need to do anything about it. we could move it the any Linux-based machine.

Everything from OS to services (ex Nginx) and its configurations are packaged into a container, that we can run anywhere. This is why the Docker is more powerful.

By providing the below command, we can see how much CPU, and memory are utilized by the container

sudo docker stats
docker stats

Why docker containers are super fast?

  • Here now we all have questions like How the boot-up is so fast, why is it so fast, and how we create containers so quickly, What is behind it?
  • The answer is very simple, it needs only one kernel. if we are using docker in Linux all the container’s OS will be Linux-based they are sharing the underlying Linux kernel.
  • Here in our case, the underlying operating system is Ubuntu. When we installed it running off the Linux kernel. It is the same kernel all the container’s OS would use.
  • As it does not require more than one kernel, it is lightweight, and so fast.
  • One thing I want us to know is, we could not install Windows containers on Linux. Docker containers are available for the Windows version, but we could only install Windows-based containers in Windows-based systems. the same goes for Linux, Linux-based containers only be installed in a Linux-based system. because all the containers going to use its underlying operating system and Kernel.

What makes VMs Slow?

  • But in VM (VMware) each virtual machine has its own Linux/windows kernel there are running. because they are virtual machines.
  • Every time we set up a new virtual machine, that is another Linux/windows kernel and then the operating system (OS). And it also involves Hypervisors.
  • It is overall heavy because some more parts or pieces have to be running to make the VMs work. whereas a container container is simple and lightweight.

Hope you enjoyed the read! 🚀 Docker containers are a fast, lightweight alternative to virtual machines💻. Give Docker a try and experience the efficiency firsthand! 🎉 Happy Dockering!

Video Reference

--

--

Bennison J
YavarTechWorks

👩‍💻 Software Engineer 🚀 UNIX/Linux ♥️ | JavaScript/Node.js 🔥 | SQL 📊 | Backend Developer 💻 | Tech Blogger ✍️ | Tech Enthusiast 🌟 |Continuous Learner 📚