Docker
Understand OS-level container isolation, Docker Images, volumes, networks, and where containers differ from VMs.
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:80from 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.
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.