Docker Tutorial: Introduction (2026 Edition)
What is Docker?
Docker is an open-source platform that lets you build, ship, and run applications inside lightweight, portable containers. A container packages your code together with its dependencies, so it runs identically on a laptop, a CI runner, or production. This tutorial takes you from the basics to advanced topics, fully refreshed for 2026 — including multi-stage builds, Compose v2, BuildKit, and container security.

Containers vs. Virtual Machines
VMs virtualize hardware and run a full guest OS — heavy and slow to start. Containers virtualize the OS and share the host kernel — lightweight, fast, and dense. That efficiency is why containers became the foundation of modern cloud-native infrastructure.
Benefits of Docker
- Portability — run anywhere Docker runs.
- Consistency — “works on my machine” becomes “works everywhere”.
- Isolation — each container has its own filesystem, network, and processes.
- Efficiency — start in milliseconds, pack many per host.
- Ecosystem — millions of ready-made images on Docker Hub.
Installing Docker
# Ubuntu — install Docker Engine
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker $USER # run docker without sudo (log out/in after)
# Verify
docker --version
docker run hello-worldOn Windows and macOS, install Docker Desktop, which bundles the engine, CLI, and Compose. Need Kubernetes locally too? See our Minikube install guide.
Core Docker Concepts
- Image — a read-only template for a container.
- Container — a running instance of an image.
- Dockerfile — the recipe used to build an image.
- Registry — where images are stored and shared (Docker Hub, GHCR, ECR).
- Volume — persistent storage that outlives the container.
- Network — how containers talk to each other and the outside world.
Essential Docker Commands
docker pull nginx # download an image
docker run -d -p 8080:80 nginx # run a container in the background
docker ps # list running containers
docker ps -a # list all containers
docker images # list images
docker exec -it <id> bash # open a shell inside a container
docker logs <id> # view container logs
docker stop <id> && docker rm <id> # stop and remove
docker system prune -a # clean up unused images/containersWriting a Dockerfile
# A simple Node.js app image
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]docker build -t myapp:1.0 .
docker run -d -p 3000:3000 myapp:1.0Multi-Stage Builds (Smaller, Safer Images)
Multi-stage builds keep build tools out of your final image, dramatically reducing size and attack surface — a 2026 best practice.
# Stage 1: build
FROM golang:1.22 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app
# Stage 2: minimal runtime
FROM gcr.io/distroless/static
COPY --from=build /app /app
ENTRYPOINT ["/app"]Docker Compose (v2)
Compose defines and runs multi-container apps. In 2026 it’s invoked as docker compose (a built-in plugin, no hyphen).
# compose.yaml
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: secret
volumes:
- dbdata:/var/lib/postgresql/data
volumes:
dbdata:docker compose up -d
docker compose ps
docker compose logs -f
docker compose downVolumes & Networking
# Persistent data with a named volume
docker volume create appdata
docker run -d -v appdata:/data myapp:1.0
# Create a network and connect containers
docker network create appnet
docker run -d --network appnet --name api myapp:1.0Container Security Best Practices (2026)
- Use minimal base images (Alpine, distroless) and pin versions.
- Run as a non-root user (
USERin the Dockerfile). - Scan images for CVEs with
docker scout, Trivy, or Grype. - Never bake secrets into images — use build secrets or runtime injection.
- Sign and verify images with Cosign for supply-chain security.
Go deeper with our guides on Docker Security Scanning, Managing Secrets in Docker, and Docker Container Monitoring.
From Docker to Kubernetes
Docker is perfect for building and running containers, but production at scale needs orchestration. That’s where Kubernetes comes in — handling scheduling, scaling, self-healing, and rollouts. See Docker Compose vs Kubernetes and our Kubernetes Tutorial for the next step.
Conclusion
Docker is still a foundational DevOps skill in 2026. Once you’re comfortable with images, Dockerfiles, Compose, volumes, networking, and security, you’ll be ready to containerize any application and move on to orchestration with Kubernetes. Practice by containerizing a real project, then test your knowledge with our 50 Docker Interview Questions & Answers.

