A container packages an application together with its dependencies (runtime, libraries and configuration) into a single, immutable image that runs the same way on a laptop, in a test environment and in production.

As environments became rules-based and API-driven, it became possible to wrap up an application and its environment into a single package and simply move it from place to place. This containerisation means we can progress environments, not just code, through development, test and production as part of an iterative build.

How containers work

Unlike a virtual machine, a container doesn’t include a whole operating system. Containers share the host’s kernel and use operating system features to isolate processes, file systems and networking from each other. That makes them:

The key concepts are:

Virtual machines compared with containersVirtual machinesContainersAppLibrariesGuest OSper VMAppLibrariesGuest OSper VMAppLibrariesGuest OSper VMHypervisorInfrastructureAppLibrariesAppLibrariesAppLibrariesContainer runtimeHost OS (shared kernel)Infrastructure
Virtual machines each carry a full operating system; containers share the host's kernel and package only the application and its dependencies.

Orchestration

Running one container is easy. Running hundreds of them reliably, with scaling, networking, rolling deployments, health checks, secrets and service discovery, needs an orchestrator:

Following the mental model, start with serverless containers and only take on a full Kubernetes platform when you genuinely need what it offers.

When to use containers

Containers are a good fit when:

They’re less of a fit when a fully managed or serverless service already solves the problem. A container you build is still software you have to patch: base images need regular rebuilding and scanning for vulnerabilities, and you’re responsible for everything inside the image.

Good practice