Containers package an application with everything it needs to run – so it behaves the same on a laptop, a test server and production. Many tools you’ll run as an admin (monitoring, CI agents, internal web apps) are now shipped as containers.
Lab: Docker on an Ubuntu VM (
sudo apt install docker.ioor Docker’s official repository), or Docker Desktop on Windows with WSL2. Examples use Linux containers.
Container vs virtual machine
| Virtual machine | Container | |
|---|---|---|
| Includes | A whole OS with its own kernel | Just the app and its libraries; shares the host kernel |
| Start time | Minutes | Seconds |
| Size | GBs | MBs to a few hundred MB |
| Isolation | Strong (hypervisor) | Good, but weaker than a VM |
| Typical use | Servers, mixed workloads | Applications and services |
Linux containers need a Linux kernel; Windows containers run Windows apps on Windows Server. They aren’t interchangeable.
Images and containers
- An image is a read-only template (like a VM template):
nginx:1.27,prom/prometheus. - A container is a running instance of an image. You can run many containers from one image.
- Images come from a registry – Docker Hub, or your company’s private registry.
Everyday commands
docker pull nginx:1.27 # download an image
docker run -d --name web -p 8080:80 nginx:1.27 # run in background, map host 8080 → container 80
docker ps # running containers
docker ps -a # including stopped
docker logs -f web # follow logs
docker exec -it web sh # open a shell inside
docker stop web && docker rm web # stop and remove
docker images # local images
docker image prune # remove unused images
Open http://<host>:8080 – nginx answers.
Data: containers are disposable, volumes aren’t
When you remove a container, anything written inside it is gone. Keep data in volumes or bind mounts:
docker volume create grafana-data
docker run -d --name grafana -p 3000:3000 -v grafana-data:/var/lib/grafana grafana/grafana
docker run -d --name web -p 8080:80 -v /srv/site:/usr/share/nginx/html:ro nginx:1.27
Now you can upgrade the container (remove and run a newer image) without losing data.
Build your own image
Dockerfile:
FROM nginx:1.27
COPY site/ /usr/share/nginx/html/
EXPOSE 80
docker build -t winops/demo-site:1.0 .
docker run -d -p 8081:80 winops/demo-site:1.0
Each instruction creates a layer; layers are cached, so rebuilds are fast.
Docker Compose: several containers together
compose.yaml:
services:
prometheus:
image: prom/prometheus
ports: ["9090:9090"]
volumes: ["./prometheus.yml:/etc/prometheus/prometheus.yml"]
grafana:
image: grafana/grafana
ports: ["3000:3000"]
volumes: ["grafana-data:/var/lib/grafana"]
volumes:
grafana-data:
docker compose up -d
docker compose logs -f
docker compose down
This is how you’d run the Prometheus and Grafana lab in one command.
Good habits
- Pin versions (
nginx:1.27, notlatest) so updates are deliberate. - Use official or trusted images; scan them for vulnerabilities in your pipeline.
- Don’t put secrets in images – pass them at runtime.
- Run as a non-root user inside the container where possible.
FAQ
Will containers replace our Windows servers? Not wholesale. Many Windows apps still run best on VMs. Containers shine for new apps, tools and services that are built for them.
What’s next
Next: Kubernetes concepts for infrastructure engineers.
Practise this topic
Test yourself with free questions on this topic – instant answers and explanations.
Start practice questionsDockerContainersDevOpsIntermediate