Skip to main content
Last time we saw how virtual machines let one physical computer act like many by running full operating systems side by side. That approach is powerful but can be slow: each VM boots an entire guest OS before your app runs.
The image shows a person standing next to a digital representation of laptops connected to a VM (virtual machine) box, with Apple and Windows logos on the laptop screens.
Booting a VM adds noticeable overhead. If you only need to run a single process or quickly scale many identical services, starting a full OS each time is overkill.
The image shows a person standing next to a graphic of a laptop displaying virtual machines, with the KodeKloud logo on their shirt.
Containers solve this by removing the guest OS from the runtime path. They package an application and its dependencies and launch in seconds.
The image illustrates two containers labeled "App01" and "App02" with a cartoon cat standing on them. It includes the text "Containers don’t have their own OS," and a person is standing on the right side.
In this lesson we’ll:
  • Define what a container is and how it isolates a single application.
  • Explain why containers are popular (speed, portability, consistency).
  • Cover storage and networking basics for containers.

What is a container?

A container is a lightweight, self-contained environment for running one application or service. It bundles the application code, runtime, libraries, and configuration so the app runs predictably across environments. Crucially, a container does not include a full guest OS. Instead it shares the host machine’s OS kernel—the component that schedules CPU, manages memory, and controls hardware access.
The image shows a person standing in front of a graphic depicting a computer screen with a container symbol crossed out, and a "Host Kernel" label. The person is wearing a "KodeKloud" t-shirt.
Most containers rely on Linux kernel features (namespaces, cgroups) for isolation and resource control, so Linux is the dominant platform. On macOS and Windows, tools like Docker Desktop run a lightweight Linux VM behind the scenes so you can use Linux-based containers. Windows also supports native Windows containers that use the Windows kernel. Think of a container as a super-powered process: isolated from other processes, carrying its dependencies, and fast to start and stop.

Images and Dockerfiles

Every running container is an instance of an image. An image is an immutable, read-only snapshot that defines the filesystem, runtime, and the command to run. You can launch many containers from the same image. Images are usually built from a Dockerfile (or equivalent). A Dockerfile is a small declarative script telling a container engine how to assemble the image. Docker is a widely used tool for building and running images; alternatives include Podman and runtimes like containerd. Example Dockerfile:
Once you build an image, you can run one container or thousands; each behaves like a clean, standalone application instance you can start, stop, pause, or remove without altering the host system.
The image shows a graphic of a laptop with containers and a user interface labeled "Standalone App" with options: Start, Stop, Pause, and Delete, alongside a person in a KodeKloud shirt.
Networking: containers communicate with each other and the outside world over virtual networks. Container runtimes like Docker create default networks so containers in the same group can communicate. For multi-service setups, orchestration tools such as Docker Compose and Kubernetes handle launching, scaling, service discovery, and network policies.
The image shows a person standing next to a diagram illustrating Docker containers emerging from a laptop, with the Docker logo prominently displayed.

Why containers matter

Containers address several practical needs for modern development and operations:
The image shows a person standing next to a digital illustration of containers, Kubernetes, and Docker Compose, with related functionalities like launching, scaling, and connecting.
  • Fast startup: No guest OS to boot, so apps can start in seconds—useful for development and autoscaling.
  • Consistency: Images provide identical runtime environments across machines, reducing “works-on-my-machine” problems.
  • Portability: Build an image once and run it wherever the container runtime is supported.
  • Isolation: Containers isolate the app and its dependencies from other host applications.
The image shows two laptops with "Container" and cog graphics on the screens, connected by the word "Same." A person stands next to them, and words "Portable," "Anywhere," and "Across Platform" are displayed at the top.
If you prefer a quick comparison:

Limitations and trade-offs

Containers share the host kernel, so their isolation is not as strong as a VM’s hardware-level separation. A kernel-level vulnerability could potentially affect other containers or the host. Containers are commonly used for single services; running large monoliths is possible but may require different patterns and operational controls.
Containers share the host kernel. For multi-tenant or high-security scenarios, harden the host, minimize the attack surface, or consider VMs for stronger isolation.

Data persistence

By default, containers are ephemeral: files written to a container’s internal filesystem are lost when the container is removed. Treat the container’s writable layer like a temporary workspace.
The image features a graphical container with a crossed-out folder icon and the text "Data Persistence is a DOWNSIDE." A person is standing next to it, wearing a KodeKloud t-shirt.
To keep data beyond a container’s lifecycle, attach volumes. Volumes are external storage that persist independently of container instances and are the recommended way to store databases, logs, or user uploads.
Use volumes to persist important data. Volumes exist outside the container’s writable layer, so removing a container won’t delete the stored data.

Quick quiz

Which statement is true? A. A container includes its own full operating system.
B. Containers always save their data, even after they’re deleted.
C. A container runs in an isolated environment using the host’s operating system kernel.
Answer: C. Containers run in isolated spaces but share the host kernel. A is false (containers don’t include a full guest OS). B is false unless you attach persistent storage such as volumes.

Summary

The image explains that containers do not save data by default when they stop, and emphasizes the need to connect a volume to retain data. A person stands beside the explanation, wearing a "KodeKloud" shirt.
  • Containers typically run a single app or service in an isolated environment.
  • They share the host OS kernel instead of bundling a full guest OS.
  • Containers start quickly, behave consistently across environments, and avoid dependency conflicts.
  • Containers communicate over virtual networks and can be orchestrated at scale with tools like Kubernetes.
  • Use volumes to persist data long-term.
Next up: we’ll compare containers to virtual machines in detail and discuss when to use one or the other.
The image shows a person speaking, with diagrams of containers and a virtual machine (VM) on a black background. The person is wearing a T-shirt with the "KodeKloud" logo.

Watch Video