> For the complete documentation index, see [llms.txt](https://kmanu225.gitbook.io/cs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kmanu225.gitbook.io/cs/software-engineering/unix-linux-on-windows-choosing-the-right-environment/docker-and-containers-reproducible-linux-environments-on-windows.md).

# Docker and Containers: Reproducible Linux Environments on Windows

[WSL](/cs/software-engineering/unix-linux-on-windows-choosing-the-right-environment/wsl-a-real-linux-environment-inside-windows.md) gives you a general-purpose Linux environment. **Containers solve a different problem: they package an application together with its runtime and dependencies.**

The goal is not simply to "get Linux", but to create an environment that can be reproduced on another developer machine, in CI, or in production.

## When should you use containers?

Containers are a good choice when:

> You want an application to run in a controlled and reproducible environment.

For example, a project can define its environment in a `Dockerfile`:

```dockerfile
FROM python:3.13

WORKDIR /app
COPY . .

RUN pip install -r requirements.txt

CMD ["python", "app.py"]
```

Instead of manually installing the same runtime and dependencies on every machine, developers and CI can use the same container image.

Typical use cases include:

* web applications;
* microservices;
* databases and supporting services;
* CI/CD pipelines;
* reproducible builds and tests.

## Containers are not virtual machines

A virtual machine emulates a complete computer and runs its own guest kernel.

A container is different: it runs as a set of processes on an existing kernel.

The kernel isolates those processes using mechanisms such as:

* **namespaces**, which give containers separate views of processes, networking, mounts, and other resources;
* **control groups**, which limit and account for CPU, memory, and other resource usage;
* isolated filesystems and network interfaces.

Conceptually:

```
Virtual machine
    -> virtual hardware
    -> guest kernel
    -> guest userspace
    -> application

Container
    -> host kernel
    -> isolated processes and userspace
    -> application
```

So each container can appear to have its own filesystem, process tree, hostname, and network stack, even though all containers ultimately use the same underlying kernel.

This is why containers are usually lighter than virtual machines: they do not need to boot and maintain a separate kernel for every instance.

It also explains an important limitation:

**a Linux container needs a Linux kernel.**

On a native Linux host, containers use the host Linux kernel directly. On Windows, Docker must therefore provide a Linux kernel through a virtualization backend.

## Docker Desktop on Windows

On Windows, **Docker Desktop** is the most common way to run Docker.

Linux containers require a Linux kernel, so Docker Desktop provides one using a virtualization backend.

On modern Windows, that backend can include:

```
Docker Desktop
    |
    +-- WSL 2
    |
    +-- Hyper-V
    |
    +-- Docker VMM
```

This means the actual architecture is closer to:

```
Windows
    |
    +-- Linux VM / virtualization backend
           |
           +-- Linux kernel
                  |
                  +-- container
                  +-- container
                  +-- container
```

The containers share the Linux kernel provided by that backend. They do **not** directly share the Windows kernel.

## WSL or Docker?

Use **WSL** when you want:

> a general-purpose Linux development environment.

Use **Docker** when you want:

> an isolated and reproducible environment for a specific application or service.

They are often used together, but they solve different problems.

## Should you use containers?

Use containers when your requirement is:

> **"I want this application and its dependencies to run consistently across development, CI, and production."**

If instead you need a complete Linux machine with its own kernel and operating-system configuration, a traditional virtual machine is a better fit.
