đłđ»Difference between VMs and Docker, and why newbies should care?
You start your ambitious plans to learn Docker â youâll be an amazing DevOps after all! You learn all of the Dockerfiles configurations, the youtube courses (Docker in 10 hours is an absolute classic!), and you finally, finally, land an interview â so hard in year 2024. And then⊠you donât get the questions how to make a Dockerfile, how to run an image. The question is:
What is the difference between a Virtual Machine and Docker?
It seems logical, right? After all, you fire up a virtual machine, and there it is â a full operating system, all ready to go. Then you hear about Docker, and itâs doing something with containers, but no one really hands you an OS when you start a Docker container, so it must be different, right? âDocker doesnât need an operating system!â You say, or even worse: âDocker replaces Virtual Machines!â.
Of course. A Virtual Machine is indeed a complete emulation of a physical computer. It allows you to run an operating system and applications as if they were on a physical machine, while in reality, they are running on a host system. Beautiful. Now for the Docker partâŠ
âDocker doesnât need an Operating System!â
Yeah, but no. True, Docker doesnât require a full operating system for each container like a Virtual Machine does. But absolutely be prepared for a follow up question: âThen what does Docker use to run containers?â The answer to save face is that Docker uses the host operating systemâs kernel to run containers. This is a critical point to understand when comparing Docker to Virtual Machines. This means you cannot run a Windows app on your Docker container if you have a Linux system on the host!
Note: Docker enables cross-platform functionality, allowing Linux containers to run on Windows hosts via Windows Subsystem for Linux 2 (WSL2). However, Windows containers can only run on Windows hosts with the appropriate Windows kernel; they cannot be executed on Linux hosts. But on that, you can read in the future article.
âDocker replaces Virtual Machinesâ
Good God, this one is a one-way ticket to the CV shredder.
Okay, so: VMs run on a hypervisor and include a full operating system, which means each VM is self-contained and runs its own kernel. This makes VMs heavier in terms of resource usage since they require more disk space, memory, and processing power. Docker containers share the host OS kernel, as already mentioned above, and run isolated processes in user space. This makes containers lightweight, as they donât need a full OS for each instance, allowing for quicker startup times and less overhead. So why not just replace VMs with Docker?
One of the answers is above: The kernel. VMs are often used in scenarios where full OS environments are needed, such as legacy applications, resource-intensive applications that require complete isolation, or when running different OS environments on a single physical machine.
Or just safely test that spooky virus youâve seen circulating on the internet.