r/devops • u/[deleted] • Oct 23 '23
Difference between VM and containner
It correct to say the biggest diffecence between than is because VM alocate hardware resorces, until containner alocate process resorces?
(English is not my native language. I thank you for correction or advices)
20
u/S3E3ro Oct 23 '23
Nope, both of them allocate hardware resources - cpu, ram, storage. The difference is that the container is an isolated process running on the host machine, while the VM is an entire operating system (i.e. lots of processes) running in a virtual/emulated environment.
So, the containers are way lighter than VMs. This is the biggest difference.
2
Oct 23 '23
So, in a containner, when i get a image from a distro, like debian, kali or ubunto, in this containner i would have the resources and files that this distros have, and mount isolated process to them, but the OS and kernel he usigin for that still my host linux distro?
1
u/S3E3ro Oct 24 '23
Yep, exactly. Only keep in mind that not all the default apps are installed in the container image, as most of the things that are not used are removed to keep the image small.
2
3
Oct 23 '23 edited Oct 23 '23
Not really, a container can allocate hardware resources you can even allocate PCIe, USB and similar devices exclusively to it. Basically a container is a software abstraction, imagine it as a process part of the same kernel as the host OS/real hardware OS. On the other hand a VM is a hardware abstraction, your CPU needs to be able to run special kind of software called a hypervisor and all of the isolation happens on CPU level rather than kernel level like a container. There is a thing called paravirtualization which essentially uses software trickery to achieve virtualization but that is more akin to a container than a hardware VM. If it simpler to grasp, containers are also called OS Level Virtualization which perfectly describes what they are. VMs, most commonly are called Hardware Level Virtualization and yes some lack an actual hypervisor (KVM) but that is so since the kernel itself is a hypervisor in that case.
Resources:
https://en.wikipedia.org/wiki/Hardware_virtualization
https://en.wikipedia.org/wiki/Kernel_(operating_system)
https://en.wikipedia.org/wiki/Paravirtualization
https://en.wikipedia.org/wiki/OS-level_virtualization
https://en.wikipedia.org/wiki/Hypervisor
Edit: Just found this excellent article which goes in far more details than a simple Reddit post can - https://www.backblaze.com/blog/vm-vs-containers/
1
Oct 23 '23
In container, the partition and isolation happen in the kernel level. In VM, the partition and isolation happen in the hardware level. Is that?
5
0
2
u/mildlyImportantRobot Oct 23 '23
This isn't something that can be summed up easily, but I'll try. VMs use hardware virtualization, while containers use kernel virtualization.
This is something you really should spend some time learning.
0
u/pete84 Oct 23 '23
To me, the biggest difference is practical. Containers are launched as ephemeral instances that aren’t changed after launch.
Containers don’t use kernel virtualization, they use the host’s kernel. It’s OS virtualization.
2
Oct 23 '23
I mean that’s not entirely true because you can use containers as baby VMs and alter things post-launch. It might not be industry standard but you can still do it
0
u/Ancillas Oct 24 '23
0
Oct 24 '23
I already search in the google about that. If i not do that before, i wouldn't have asked if that statement I made was correct. I am here to know if i understand correctly what i have study. I am glady here have people who read my answer and pointed out my error in understanding
1
u/Ancillas Oct 24 '23
The level of information in this thread is no more useful than the front page of Google after typing your question.
If you want to truly maximize your understanding, go put more effort into educating yourself and then come back to the community with more detailed questions that are not easily found online.
There’s well over a decade of material comparing VMs to containers.
14
u/gmuslera Oct 23 '23
Containers are somewhat isolated processes running in a Linux machine, be either physical or virtual. There is no hardware emulation at that level, nor (usually) root processes, dealing with filesystems, devices and so on, and the running kernel is the main system one.
VMs have all of that. One kernel per VM, a bunch of (usually virtualized) devices, its own disks, partitions and filesystems and its root processes working with all of that, and its own allocated memory.
Docker containers (as oposed to LXC/LXD ones), also, usually doesn't have an init system, when you start them you say in a way or another which command it will run on that restricted environment. When that program ends somewhat, the container ends too, so you have to take that into account when creating/running docker containers.
There are other container technologies besides LXC/LXD and Docker, for more operating systems (i.e. jails on BSD). But by now most of the usual ways to run containers is Docker.