Understanding Docker: Containers vs VMs
Let's dive into the world of Containers
In a world where technology evolves faster than we can keep up, Docker has emerged as a game changer in software development. But what exactly is Docker and why are companies and developers using it around the world? In this blog, we'll have a look at what is Docker, explore the concepts of containers, and try to differentiate between containers and traditional virtual machines. As this is my first blog on Docker, I won't go into what images, volumes, networks are and all. Let's take one step at a time and try to understand Docker in depth!
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!
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!
Thank you for staying till the end!