No history yet

Introduction to Containers

What Are Containers?

Think about global trade. Before the 1950s, loading a ship was a chaotic, piece-by-piece process. Then came the standardized shipping container. Suddenly, everything from textiles to electronics could be packed into the same type of box, making them easy to stack, move, and transport anywhere in the world.

Software containers do the same thing for applications.

Lesson image

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. This package includes everything needed to run: libraries, system tools, code, and runtime.

Think of a container as a standardized box that holds your application and everything it needs to run consistently, regardless of where the container is deployed.

This solves the classic problem of, "Well, it works on my machine!" By bundling the application with its environment, containers ensure consistency. Whether on a developer's laptop, a testing server, or in the cloud, the application behaves the same way. This makes them incredibly portable and efficient.

Containers vs. Virtual Machines

You might be thinking this sounds a lot like a Virtual Machine (VM). VMs also provide isolated environments to run software. However, they work in a fundamentally different way, and the difference is crucial.

A VM virtualizes the hardware. It runs a complete, independent guest operating system on top of a host OS. This means each VM includes not just the application and its dependencies, but an entire OS, which can be gigabytes in size.

Containers, on the other hand, virtualize the operating system. They sit on top of a host OS and share its kernel, but run as isolated processes in user space. They only package the specific libraries and dependencies required by the application, making them far more lightweight.

This architectural difference has significant consequences. Because containers are so much lighter, you can run many more of them on a single host compared to VMs. They also start up in seconds, rather than the minutes it can take to boot a full OS in a VM.

The key insight: containers share the host's OS kernel but run as isolated processes, while VMs each have their own OS.

FeatureVirtual MachinesContainers
IsolationFull OS isolationProcess-level isolation
SizeGigabytesMegabytes
Startup TimeMinutesSeconds
Resource UsageHigh (Full OS)Low (Shared OS kernel)
PortabilityModerateHigh

Container Runtimes

To create, run, and manage containers, you need a container runtime, sometimes called a container engine. This is the underlying software that handles the heavy lifting.

By far the most well-known container runtime is Docker. It popularized the use of containers and has become the de facto industry standard. When people talk about containers, they often use the word "Docker" interchangeably.

Lesson image

The runtime's job is to manage the lifecycle of containers. This includes building containers from a set of instructions (called an Image), starting them, stopping them, and removing them. Here are a few of the most basic commands you'd use with Docker to manage a container running a simple web server:

An Image is a read-only template with instructions for creating a container. A Container is a runnable instance of an image.

# Pull an image from a registry (like Docker Hub)
docker pull nginx

# Run a container from the image
# -d: run in detached mode (in the background)
# -p 8080:80: map port 8080 on the host to port 80 in the container
# --name my-web-server: give the container a name
docker run -d -p 8080:80 --name my-web-server nginx

# List running containers
docker ps

# Stop the container
docker stop my-web-server

# Remove the container
docker rm my-web-server

While Docker is the most common, other runtimes like containerd and CRI-O also exist and are widely used, especially within more complex systems like Kubernetes. For now, understanding the role of Docker is enough to grasp the core concepts.

Quiz Questions 1/5

What common developer problem is directly solved by the consistency that software containers provide?

Quiz Questions 2/5

The main difference between a container and a Virtual Machine (VM) is that a container virtualizes the operating system, while a VM virtualizes the hardware.

This lightweight, portable nature is why containers have become the foundation of modern cloud applications. They provide the perfect building blocks for scalable and resilient systems.