Docker, Containers, Images & Virtual Machines
Docker, Containers, Images & Virtual Machines
Introduction
Docker, containers, container images, and virtual machines are closely related concepts, but they are not the same thing.
Understanding their differences is one of the first important steps in learning Docker and modern cloud-native engineering.
A useful way to think about the relationship is:
Application
│
Dockerfile
│
▼
Container Image
│
▼
Container
│
Alternative deployment model
│
▼
Virtual Machine
What problem is Docker solving?
- Docker is an open platform for developing, shipping, and running applications.
- Package the application and its dependencies together, then run that package as a container.
What Is a Container?
A container is a runnable instance of a container image.
Docker's current documentation describes a container as an isolated process with the files it needs to run. Containers can be independently managed and can share the host kernel when using the Linux container model.
docker run nginx
Conceptually:
nginx Image
│
│ docker run
▼
nginx Container
│
▼
Nginx Process
What Is a Container Image?
A container image is a standardized package containing the files required to run an application.
For example, a Python application image could contain:
Python runtime
+
Python packages
+
Application code
+
Configuration
+
Required system libraries
Docker describes images as immutable and layered. Each layer represents filesystem changes that add, modify, or remove files.
A simplified image might look like:
┌──────────────────────────────┐
│ Application Code
├──────────────────────────────┤
│ Python Dependencies
├──────────────────────────────┤
│ Python Runtime
├──────────────────────────────┤
│ Base Image
└──────────────────────────────┘
Image vs Container
This is one of the most important distinctions for beginners.
| Concept | Image | Container |
|---|---|---|
| Purpose | Package application | Run application |
| State | Immutable | Runtime state can change |
| Execution | Does not run by itself | Runs a process |
| Storage | Image layers | Image + writable container layer |
| Relationship | Template | Instance |
| Example | nginx:latest | my-nginx |
What Is a Virtual Machine?
A virtual machine is a virtualized computer system running on a physical or virtualized host.
A simplified architecture is:
A VM has its own operating-system environment, including its kernel.
Docker's documentation describes a VM as an entire operating system with its own kernel, drivers, programs, and applications.
Why Containers Can Be Lightweight
A VM typically includes an entire guest OS environment.
A container does not need to package another complete Linux kernel when running as a Linux container on a Linux host.
Container
Application
↓
Container filesystem
↓
Container isolation
↓
Host Linux Kernel
This is one reason containers can be lightweight compared with full VMs.
Docker's documentation states that multiple containers can share the host kernel, allowing more applications to run on the same infrastructure in suitable workloads.
Important: lightweight does not mean "no isolation." Containers use kernel-level isolation mechanisms, and their security depends on the kernel, container configuration, Docker daemon, and other controls.