Before containers, teams shipped software by handing operations a set of installation instructions, or a whole virtual machine. Both were slow and fragile: "it works on my machine" was a daily problem. Containers fixed this by packaging an application together with everything it needs, in a format that runs the same on a laptop, a CI runner and a production server. This lesson explains what a container actually is and how it differs from a virtual machine.
In simple words
- Container: a packaged app with everything it needs (code, libraries, settings) that runs as an isolated process on a shared Linux kernel. It starts in seconds.
- Virtual machine (VM): a whole pretend computer with its own operating system, running on a hypervisor. Heavier and slower to start than a container.
- Hypervisor: the software that creates and runs virtual machines, such as VMware, KVM or the cloud's own.
- Isolation: keeping one app from seeing or affecting another, even though they share the same machine.
The problem containers solve
Imagine a Java service that needs Java 21, a specific version of OpenSSL and a config file in /etc/app. On your laptop it works. On the test server, Java 17 is installed, so it fails. On production, someone upgraded OpenSSL last week, so it fails differently.
A container image bundles the app and its runtime, libraries and files into one artifact. Wherever the image runs, the app sees exactly the same environment.
| Without containers | With containers |
|---|---|
| Install runtimes on every server by hand | The runtime is inside the image |
| Different library versions everywhere | Identical files everywhere |
| Deploy = run a script and hope | Deploy = run the image |
| Rollback = reinstall the old version | Rollback = run the previous image tag |
Virtual machines in one minute
A virtual machine (VM) emulates a complete computer. A hypervisor (VMware ESXi, KVM, Hyper-V, or the one behind every EC2 instance) divides physical hardware into several virtual machines, and each one boots its own full operating system.
- Each VM has its own kernel, so you can run Windows and Linux side by side.
- Isolation is strong: a bug in one guest kernel does not affect another.
- But every VM carries a full OS: gigabytes of disk, hundreds of MB of RAM before your app even starts, and boot times in minutes.
Containers in one minute
A container is an isolated process running on the host's own Linux kernel. There is no guest OS and no emulated hardware. The kernel uses two features to make the process feel like it has its own machine:
| Kernel feature | What it isolates or limits | Example |
|---|---|---|
| Namespaces | What the process can see: its own process list, network, hostname, files | Inside the container, ps shows only the app |
| cgroups | What the process can use: CPU, memory, number of processes | --memory 512m caps the container's RAM |
On top of that, the container's files come from an image: a read-only bundle of the app and its dependencies.
Side by side
| Virtual machine | Container | |
|---|---|---|
| What is virtualised | Hardware | The operating system view |
| Kernel | Its own guest kernel | Shares the host kernel |
| Typical size | 1–20 GB | 5–500 MB |
| Start time | 30 seconds to minutes | Milliseconds to a few seconds |
| Density | Tens per server | Hundreds per server |
| Isolation | Strong | Good, but a shared kernel means kernel bugs matter |
| Can run a different OS? | Yes (Windows on Linux host) | Only Linux containers on a Linux kernel* |
*Docker Desktop on macOS and Windows quietly runs a small Linux VM to host Linux containers. That is why containers "work" there too.
They are not competitors
In practice you use both together. Your containers run inside VMs: an EKS worker node is an EC2 virtual machine running dozens of containers. The VM gives strong isolation between customers and teams; containers give fast, dense, repeatable app packaging inside it.
Your first container
In the practice terminal, run:
docker run --rm hello-worldHello from Docker!This message shows that your installation appears to be working correctly.docker runcreates and starts a container from an image.--rmdeletes the container automatically when it exits.hello-worldis a tiny image whose only job is to print that message.
Now start something longer-lived and look at it:
docker run -d --name web -p 8080:80 nginxdocker psCONTAINER ID IMAGE STATUS PORTS NAMES3f9a1c2b7d4e nginx Up 2 seconds 0.0.0.0:8080->80/tcp webA full web server started in about a second. A VM with nginx would still be booting.
Proving it is just a process
On a Linux host (a live lab), the container's process is visible from the host like any other program:
$ ps -ef | grep "nginx: master"root 48213 48190 0 10:02 ? 00:00:00 nginx: master process nginx -g daemon off;Inside the container, the same process thinks it is PID 1 and sees nothing else. Same process, two different views: that is a namespace at work. You will take this apart in the Expert section of this course.
Real-world scenario
A team runs 12 microservices. With one VM per service they paid for 12 VMs that were 90% idle, deploys took 20 minutes, and environments drifted apart. After containerising:
- All 12 services run as containers on 3 larger VMs (an EKS node group).
- A deploy pulls a new image and swaps containers in under a minute.
- The image tested in staging is byte-for-byte the image in production.
Common mistakes
- Treating a container like a VM: installing SSH, running many services in one container, or logging in to patch it. Containers should be replaced, not repaired.
- Assuming containers are a security boundary as strong as VMs. They share a kernel; harden them (covered in the security lesson) and use VMs or sandboxed runtimes between untrusted tenants.
- Storing important data inside the container. It disappears with the container unless you use volumes.
Practice
- Run
hello-worldwith--rm, then rundocker ps -aand confirm no container was left behind. - Start nginx with
docker run -d --name web -p 8080:80 nginxand list running containers. - In one sentence each, explain what namespaces and cgroups do.
- Explain why an EKS worker node is both a VM and a container host.
Cheat sheet
| Command | What it does |
|---|---|
docker run --rm IMAGE | Run a container and delete it when it exits |
docker run -d --name N IMAGE | Run in the background with a name |
docker ps / docker ps -a | Running / all containers |
docker version | Client and server versions |
Key takeaways
- A VM virtualises hardware and runs its own kernel; a container is an isolated process on a shared kernel.
- Namespaces control what a container can see; cgroups control what it can use.
- Containers are small, fast and repeatable, and in production they usually run inside VMs.