
Docker containers vs virtual machines: which should run your application?
Most teams asking about Docker are deciding how to package and run an application: as containers on a shared host, or as virtual machines that each carry a whole operating system. The two often run together, so the real question is which workloads go where.
Should your application run in Docker containers or virtual machines?
Quick answer
Docker containers vs virtual machines comes down to isolation. Containers share the host operating system kernel, so they start fast and pack densely; virtual machines run a full guest operating system on a hypervisor. Most new services fit containers, while other kernels, legacy software and host-bound licences need VMs. Agnotic Technologies maps each workload first.
| Criterion | Containers | Virtual machines |
|---|---|---|
| Operating system and kernel | Services built for the host's kernel; Windows containers need Windows hosts | Any guest operating system, including older or different kernels |
| State | Stateless processes, with data in managed databases or mounted volumes | Applications that keep state on local disk and expect the same server every time |
| Scaling pattern | Scale out by starting more identical copies in seconds | Scale up to a larger VM, or out more slowly from machine images |
| Isolation need | Process isolation on a shared kernel; give untrusted code its own VM or a sandboxed runtime | Separation enforced by the hypervisor |
| Licence terms | Confirm the vendor supports and licenses the product in containers | Fits licences counted per host, core or VM |
| Patching | Rebuild and redeploy the image; patch the host separately | Patch each guest operating system in place, or rebuild it from an image |
| Team skills | Image builds, registries and an orchestrator | Server administration and configuration management |
| Typical answer in a mixed estate | Containers for new and stateless services | VMs for the rest, and often as the hosts the containers run on |
What they are
What is Containers
A container packages an application with its libraries and runs it as an isolated process. NIST SP 800-190 calls containers a form of operating system virtualization combined with application software packaging. Containers share the host kernel, so they start fast and pack densely.
What is Virtual machines
A virtual machine runs a complete guest operating system on virtual hardware from a hypervisor. NIST SP 800-125 describes full virtualization as running one or more operating systems and their applications on virtual hardware. Each VM has its own kernel.
Key differences
How does each one isolate a workload?
A VM isolates a workload with its own operating system and kernel, while a container, per Docker's documentation, is an isolated process sharing the host kernel. Kubernetes calls this relaxed isolation. Sharing is lighter and faster, but one kernel flaw can reach every container.
When is a VM still required?
A VM is still required in four cases: software that needs another operating system or kernel, legacy applications that assume a full server, vendor products supported only on a VM, and licences counted per host or core. Check each with the vendor first.
What does a container security baseline include?
A container security baseline covers images, registries, orchestrators, containers and hosts, the areas NIST SP 800-190 addresses. Scan images, use small base images, run as non-root, keep secrets out of images and pull from a trusted registry. Check configuration against the CIS Docker Benchmark.
Do you need Kubernetes to run containers?
Containers do not need Kubernetes. One service runs on a single host with Docker Compose, and a handful fit a managed container service. Kubernetes, a portable open source platform for containerized workloads, pays off when you run many services or need custom scheduling.
Can containers and VMs run together?
Containers and VMs usually run together. Docker's documentation notes that cloud machines are typically VMs, and a VM with a container runtime can run several containerized applications. Many estates keep databases and vendor software on VMs and run their services in containers on VM hosts.
When to use each
When to use Docker containers
- New services and APIs built for Linux that you deploy often.
- Workloads that scale out by adding identical copies.
- Teams that want the same image in development, CI and production.
- Several small services that would each waste a whole VM.
When to use virtual machines
- Software that needs a different kernel or operating system from the host.
- Legacy applications that expect a full server, a desktop session or local state.
- Vendor products supported only on a named operating system in a VM.
- Licences counted per host, per core or per server.
- Workloads that need a hard isolation boundary from their neighbours.
What does containerizing an existing application involve?
Containerizing an existing application removes its ties to one server. Move local files and sessions to a database, object storage or volumes, read settings from environment variables and secrets from a secrets store, and use a small, non-root image rebuilt whenever its base is patched.
The application must also log to standard output, report its health and handle the stop signal, because containers are replaced, not repaired. Confirm every third-party licence is valid in containers. Failure points: data lost on restart, dropped requests on deploy and a licence audit finding.
Which sources does this comparison rely on?
- NIST SP 800-190: Application Container Security Guide (csrc.nist.gov)
- NIST SP 800-125: Guide to Security for Full Virtualization Technologies (csrc.nist.gov)
- Docker documentation: what is a container? (docs.docker.com)
- Kubernetes documentation: overview (kubernetes.io)
- CIS Docker Benchmark (cisecurity.org)