đŸłđŸ’»Difference between VMs and Docker, and why newbies should care?

Hanna ƚwida
3 min readOct 3, 2024

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?

Oh no.

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!”.

Then you get hit with the tired 1000 yard stare.

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.

You did it! We will call you back. Maybe. Probably not.

--

--

Hanna ƚwida
Hanna ƚwida

Written by Hanna ƚwida

0 Followers

Whatever-I'm-not-supposed-to-do-right-now-Dev. Poland.

No responses yet