Containers vs virtual machines

Docker · lesson 1 of 31 · 3 min read

Know what a container really is, how it differs from a VM, and why Java teams reach for one.

Open this lesson in the learning hub

Key points

  • A container is just a normal Linux process, fenced off by kernel features called namespaces and cgroups.
  • A VM boots its own kernel on a hypervisor. A container borrows the host kernel. That is the whole difference.
  • So containers start in milliseconds and cost megabytes. VMs start in seconds and cost gigabytes.
  • Isolation is weaker than a VM. Sharing a kernel means a kernel bug is a shared risk.
  • On Mac and Windows, Docker quietly runs a small Linux VM. Your containers live inside it.

Example

# a container is a process on the host, not a machine
docker run -d --name demo eclipse-temurin:21-jre sleep 300

docker ps            # containers Docker knows about
docker top demo      # the same process, with its host PID
docker stats demo    # its cgroup CPU and memory usage

docker rm -f demo

A container is a process, not a machine.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Docker course, and every lesson in it is listed on the Docker contents page.