Understanding Docker: Exploring Containers vs. Virtual Machines

Understanding Docker: Exploring Containers vs. Virtual Machines

Docker is nothing but a Container technology. It's a tool for creating and managing containers. You might be wondering what a container is. Let me explain it to you!

A Container is a package of code and all the dependencies that our project needs. And the same container always yields the same application and execution behavior. No matter where it is executed.

Why Containers?

There are several reasons for using containers:

  • We want to have the exact same environment for development and production as well. This will ensure that our application works exactly the same in production as it did in development.

  • Every team member should have the same environment when working on a project.

  • When switching between projects, tools used in Project X should not clash with those of Project Y. Say, your X project needs Nodejs 14 and Y needs Nodejs 16. No worries. Docker has your back!

Mind you, a container is a running unit of software, but first, we always create a template/blueprint for it which is called an Image. Multiple containers can be created from a single Image.

Virtual Machines

A VM is an isolated computing environment created by abstracting resources from a physical machine. It may look the same as a Docker container at first.

This is a simplified architecture of a Virtual Machine. As you can see clearly, each VM instance has its own guest OS.

VM is more like an overhead because it eats up much memory and CPU. It wastes a lot of space and tends to be slow. Most importantly, there is no single config file that you can share if you want to replicate the same environment on some other colleague's computer (In Docker, you can share the image easily, but we'll look at it afterward). Though you can reproduce the same environment on other computers, it is very tricky.

Unlike VMs, containers do not have their own guest OS, rather they run on top of the host Operating System. Containers have a very low impact on OS, they tend to be very fast and also require minimal disk space usage. And sharing and rebuilding them is easy. You just need to share the images (we'll see what images are later!), and you can reproduce the container within a matter of seconds!

Containerization vs. Virtualization

Basically, an OS has two layers viz. OS Kernel and Application. Docker(a form of containerization) utilizes the application layer whereas Virtual Machines(VM) utiizes the OS kernel and application layer. So it might be clear that Docker images have less overhead and are much smaller in size(usually in MegaBytes). However, VMs are usually in GigaBytes. Also, Docker containers start and run faster. A VM lets you run a virtual machine on any hardware. Docker lets you run an application on any operating system. It uses isolated user-space instances known as containers. Docker containers have their own file system, dependency structure, processes, and network capabilities.

These are the choices why containers have become a go-to choice for software development. There is much to Docker: images, volumes, networks, multi-container applications, docker-compose and much more. I'll surely be writing about them as well very soon!

This foundation was necessary, and now we can explore Docker further!