Docker

Understand OS-level container isolation, Docker Images, volumes, networks, and where containers differ from VMs.

5 min read 6 lesson sections
  • #containers
  • #images
  • #oci
Docker: Understand OS-level container isolation, Docker Images, volumes, networks, and where containers differ from VMs.
Concept map

Docker builds and runs containers from container images. A container is an isolated process environment that uses operating-system features such as namespaces and cgroups while sharing the host’s kernel. Unlike a VM, it does not boot a separate guest kernel. This often makes containers lighter and faster to start, while also making their isolation boundary different.

Practice task: Trace the port mapping 8080:80 from your computer to the container. After the server starts, draw the request path and label the host port and container port.

Images, containers, and registries

An image is a versioned template containing an application, its dependencies, and default startup instructions. A container is a running instance of an image, with its own process, filesystem view, and network configuration. Images are stored in registries so teams and deployment systems can retrieve the same build.

An image is assembled in layers. A Dockerfile records the build steps, such as selecting a base image, copying application files, installing dependencies, and choosing a startup command. Good Dockerfiles use a small trusted base, copy only required files, and separate dependency installation from frequently changing source files to improve build caching.

Interactive diagram

One host · replaceable container · separate volumeBuild contextBuild contextPush imagePush imagePull imagePull imageStart instanceStart instanceapp-user ↔ published-portPort mappingPort mappingMounted dataMounted dataApplication sourceApplication sourceImage buildImage buildImage registryImage registryHost OS and runtimeHost OS and runtimeRunning containerRunning containerPublished portPublished portLocal clientLocal clientPersistent volumePersistent volume
Legend

Current step

Build a reusable image

A Dockerfile and selected build context produce versioned, read-only image layers.

An image is a reusable template; a container is a running process environment. Published ports expose only the configured path, and a volume keeps selected data separate from a replaceable container.

Documentation example: addresses use the RFC 5737 ranges and ASNs use the reserved private range. Nothing here connects to a real network.

The image format and distribution conventions are based on open container standards, but an image still needs a compatible CPU architecture, operating-system kernel, and runtime environment. A Linux container does not become a Windows VM simply because both are launched with Docker.

Your first container workflow

With Docker installed, try a disposable web server:

docker run --name hello-web -d -p 8080:80 nginx:alpine
docker ps
docker logs hello-web
docker stop hello-web
docker rm hello-web

The first command downloads the image if needed, starts it in the background, and maps port 8080 on your computer to port 80 in the container. Open http://localhost:8080 to see the response. The remaining commands list the running container, inspect its logs, stop it, and remove it.

For your own application, create a Dockerfile in its project directory and build an image with docker build -t my-app:dev .. Start with a simple app, check its logs, and rebuild after changing a dependency or source file. Do not put passwords, API keys, or other secrets in the image; pass secrets through an appropriate runtime secret mechanism instead.

Data and networking

Containers are replaceable, so data that must survive a restart belongs in a volume or another durable storage service rather than only in the container’s writable layer. Published ports make a container reachable from outside its own network; publish only the ports your application needs. Containers on a user-defined network can find each other by service name, which is useful when a web app talks to a database.

What isolation does and does not promise

Namespaces provide separate views of processes, networking, and other operating-system resources. Control groups (cgroups) account for and limit resource use. These mechanisms isolate workloads, but containers share the host kernel. A privileged container, a dangerous host mount, an exposed daemon socket, or a vulnerable kernel can weaken the boundary.

Use trusted images, keep Docker and the host patched, avoid privileged mode unless it is required, run as a non-root user when practical, and publish only necessary ports. Use a VM or another stronger isolation boundary when the workload or trust model calls for it.

When Docker is useful

Containers provide repeatable development environments, isolated test services, and a convenient unit for deployment. Many teams run containers inside VMs, combining VM-level isolation with lightweight application packaging. Orchestration platforms such as Kubernetes then manage container workloads across nodes; they do not replace the hypervisor underneath those nodes.

Choose a VM when… Choose a container when…
The lab needs a separate guest OS or kernel. The goal is to package and run an application process.
The boundary should include virtual hardware and a guest OS. Fast, repeatable application startup is valuable.
You are learning operating-system installation or server administration. You need consistent app dependencies across development and deployment.

These are starting points, not universal rules. Measure the workload and select the isolation, performance, and operations model that fits.

Interactive diagram

VM includes a guest OS and kernelContainers share the host kernelvm-hardware ↔ vm-hypervisorvm-hypervisor ↔ vm-guestvm-guest ↔ vm-appcontainer-hardware ↔ container-kernelcontainer-kernel ↔ container-runtimecontainer-runtime ↔ container-acontainer-runtime ↔ container-bPhysical hardwarePhysical hardwareHypervisorHypervisorVM · guest OS + kernelVM · guest OS + kernelApplicationApplicationPhysical hardwarePhysical hardwareHost OS kernelHost OS kernelContainer runtimeContainer runtimeContainer AContainer AContainer BContainer B
Legend

Current step

A VM virtualizes hardware

The hypervisor presents virtual devices and each VM runs its own guest OS and kernel.

Both approaches provide useful isolation, but at different layers and with different trade-offs. Containers can also run inside VMs, combining application packaging with a VM boundary.

Documentation example: addresses use the RFC 5737 ranges and ASNs use the reserved private range. Nothing here connects to a real network.