Skip to content
Log In Sign Up info@muvcloud.com

The Short Answer

The difference is the kernel. A virtual machine boots its own kernel on virtual hardware that a hypervisor provides. A container has no kernel of its own: its processes run on the host's kernel, which hides the rest of the system from them. Everything else follows from that: how strong the isolation is, how fast each starts, and how many fit on one machine. The two are introduced separately in what is a virtual machine and what is a container.

How Each One Works

  • Virtual machine: a hypervisor such as KVM gives each VM virtual CPUs, memory, disks, and network cards. The guest installs a full operating system and does not see the host at all.
  • Container: the host kernel gives a group of processes their own view of files, process IDs, network, and users through namespaces, and limits their CPU and memory with cgroups. An image supplies the files; the kernel is shared.

Side by Side

ContainerVirtual machine
KernelShared with hostIts own
IsolationKernel featuresVirtual hardware
Start timeAbout a secondSeconds to a minute
Typical sizeMegabytesGigabytes
Per hostManyFewer
Guest systemLinux userland onlyAny supported system
Kernel settingsThe host'sIts own

See the Difference on a Server

uname -r
docker run --rm alpine uname -r
systemd-detect-virt

The first two commands print the same kernel version: the Alpine container runs on the host's kernel even though its files come from another distribution. On a KVM virtual server, systemd-detect-virt prints kvm, because the whole server is itself a VM with its own kernel. How KVM does that is explained in what is KVM virtualization.

Isolation and Security

All containers on a host share one kernel, so a kernel flaw can reach every one of them, and a process running as root in a container is closer to root on the host than many people assume. Membership in the docker group is root-equivalent for the same reason; see Docker without sudo. A VM's boundary is narrower: the guest talks to the host only through virtual devices. Rootless containers and tools such as Podman reduce the risk on the container side; see Podman vs Docker.

Start Time, Size, and Density

A container starts a process, not an operating system, so it is up in about a second and its image holds only the application and its libraries. A VM boots a kernel and an init system and reserves its memory. On the same hardware you can therefore run many more containers than VMs, and replace them far more quickly when you deploy.

Using Both Together

On a cloud server the two are layered. The VPS is a virtual machine: it has its own kernel and is kept apart from other customers' servers by the hypervisor. Inside it, Docker runs your applications as containers, each with its own dependencies. Kubernetes clusters are built the same way, with containers on nodes that are usually VMs. This is the normal setup, not a compromise.

Which to Pick

  • A virtual machine when you need your own kernel or kernel modules, a different operating system, strong separation between tenants, or a complete server to manage.
  • Containers to package and run applications on a server you already have: several services side by side, repeatable deployments, and quick updates. Start with what is Docker.
  • Both for most production setups on rented servers.

Between the two sit system containers, which run a whole distribution with its own init system on the shared kernel; see LXC vs Docker. The difference between an image and a running container is in Docker image vs container.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations