Docker Tutorial
Learn Docker from your first container to images, Dockerfiles, volumes, networking, Compose, security, CI/CD and real projects. 111 lessons with verified commands and quizzes.
Start learning →
of lessons completed
Getting Started
- What Is Docker? Learn what Docker is, how containers differ from virtual machines, what images and containers are, and why teams use Docker to build, ship and run software.
- Installing Docker Install Docker Desktop on Windows, macOS and Linux or Docker Engine on a Linux server, set up rootless mode, and verify the installation with docker version and hello-world.
- Your First Container Run your first container with docker run, see what happens step by step, work interactively with -it, use --rm to clean up, and read exit codes and common errors.
- How Docker Works Understand Docker's architecture: client, daemon, containerd and runc, registries, and the Linux namespaces and cgroups that isolate and limit every container.
- The Docker CLI Learn how the Docker command line is organized: management commands versus legacy aliases, built-in help, formatting output, docker info and docker system df.
- Running Containers Run containers in the background with -d, name them, publish ports with -p, pass environment variables, set restart policies, and understand stop versus kill and exit codes.
- Listing and Inspecting Learn to see what Docker is running: docker ps and its filters, docker inspect with Go templates, top, stats, port and diff, with real output and common pitfalls.
- Logs and exec Read container output with docker logs -f --tail, open a shell with docker exec -it, understand docker attach, and copy files in and out with docker cp.
- Podman, containerd, Wasm and the OCI Landscape Understand the OCI image and runtime specs, how Docker Engine, containerd and runc fit together, and where Podman, CRI-O, gVisor, Kata and WebAssembly come in.
- Docker vs Virtual Machines Compare containers and virtual machines: isolation model, kernel sharing, startup time, resource use, security trade-offs and how to choose between them.
- Docker Desktop, WSL2 and Colima Choose and tune a local Docker setup on Windows, macOS and Linux: Docker Desktop, WSL2, Colima and alternatives, resource limits and file-sharing speed.
Images
- Understanding Images Understand what a Docker image really is: layers, the manifest and config, content-addressable IDs, tags vs. digests, official images and how to inspect them.
- Pulling and Managing Images Learn to download, list, tag, filter and delete Docker images: docker pull, images, rmi, dangling images, label-filtered prune and docker search, with real output.
- Layers and the Union Filesystem See how Docker image layers work: union filesystems, copy-on-write, whiteout files, docker history, and why deleting a file in a later layer does not shrink an image.
- Choosing a Base Image Compare Docker base images: debian, ubuntu, alpine, slim variants, distroless and scratch. Learn the size vs. compatibility trade-offs, musl vs. glibc, and a decision guide.
- Tags and Registries Learn how Docker image names work: registry, repository, tag and digest. Tag images, push them to a registry, pull them back, and avoid the latest-tag trap.
- Save, Load, Export, Import Move Docker images without a registry: docker save and load for images, export and import for container filesystems, and why docker commit is usually a trap.
Dockerfiles
- Writing a Dockerfile Write your first Dockerfile and build it with docker build. Learn FROM, WORKDIR, COPY, RUN and CMD, how each line becomes a layer, and how to read build errors.
- Build Context and .dockerignore Understand the Docker build context, why COPY can only see files inside it, and how a .dockerignore file speeds up builds and keeps secrets out of images.
- FROM and RUN Master the Dockerfile FROM and RUN instructions: shell form vs exec form, chaining commands, apt-get best practices, ARG before FROM, SHELL and pipefail.
- COPY and ADD Learn Dockerfile COPY and ADD in depth: destination paths, trailing slashes, --chown, --chmod, --from, archives and remote URLs, and why COPY is the better default.
- CMD and ENTRYPOINT Learn how CMD and ENTRYPOINT differ, how they combine, why exec form matters, how to override them, and why PID 1 decides whether your container stops cleanly.
- ENV and ARG Understand ENV and ARG in a Dockerfile: build-time vs run-time variables, scope, defaults, --build-arg, cache effects, and why secrets never belong in either.
- WORKDIR, USER, EXPOSE and LABEL Learn the Dockerfile instructions that shape how a container runs: WORKDIR, running as a non-root USER, EXPOSE as documentation, OCI LABELs and STOPSIGNAL.
- HEALTHCHECK Learn how the Docker HEALTHCHECK instruction works: options, exit codes, the starting, healthy and unhealthy states, docker ps status, and healthchecks in Compose.
- The Build Cache Learn how the Docker build cache decides what to reuse, why instruction order matters, how to copy dependencies first, and how to bust or skip the cache safely.
- Multi-Stage Builds Learn Docker multi-stage builds: separate build and runtime stages, COPY --from, named stages, --target, scratch images, running tests, and real size savings.
- BuildKit and buildx Learn BuildKit and docker buildx: cache mounts, secret mounts, SSH mounts, heredocs, build checks, output types, bake files and builders, with real build output.
- Multi-Platform Images Build one Docker image that runs on amd64 and arm64: buildx --platform, manifest lists, QEMU emulation, cross-compiling stages and Apple Silicon pitfalls.
- Dockerfile Best Practices A practical Dockerfile checklist: small images, cache-friendly ordering, version pinning, non-root users, apt patterns, linting with build checks and hadolint.
- docker init and Generated Project Files Use docker init to scaffold a Dockerfile, compose.yaml, .dockerignore and README for your project, understand what each generated file does and how to adapt it.
- docker buildx bake Describe many Docker image builds in one docker-bake.hcl file: targets, groups, variables, inheritance, matrix builds, overrides, Compose files and CI use.
Containers in Depth
- The Container Lifecycle Understand every Docker container state: created, running, paused, exited, restarting. Learn create, start, stop, kill, pause, rm and restart policies with real output.
- Configuring Containers Configure Docker containers the 12-factor way: -e, --env-file, precedence rules, mounted config files, entrypoint defaults, nginx templates and secrets pitfalls.
- Resource Limits Limit memory, CPU, processes and open files in Docker containers. Learn --memory, --cpus, --pids-limit, ulimits, OOM kills (exit 137) and how cgroups enforce them.
- Signals, PID 1 and --init Learn how docker stop really works: SIGTERM and SIGKILL, why PID 1 ignores signals, zombie processes, tini and --init, STOPSIGNAL and stop timeouts.
- Users and Permissions Run containers as a non-root user, understand UID and GID numbers, fix 'Permission denied' on volumes and bind mounts, and lock down the filesystem with --read-only.
- Debugging Containers A practical workflow for broken containers: read exit codes, logs and inspect output, override the entrypoint, attach a debug sidecar to shell-less images and watch events.
- Cleaning Up Reclaim disk space safely: docker system df, container, image, volume, network and build-cache prune, label and age filters, log rotation and automation.
- Checkpoint/Restore, live-restore and the Live Migration Myth Learn what docker checkpoint (CRIU) can and cannot do, how daemon live-restore keeps containers alive during upgrades, and why containers do not live-migrate.
- GPUs and Devices in Containers Give containers access to host hardware: --device, device cgroup rules, --gpus with the NVIDIA Container Toolkit, CDI, Compose GPU reservations and AMD or Intel GPUs.
- Namespaces, cgroups and Container Internals Look under the hood of a container: Linux namespaces, cgroups v2, user namespaces, capabilities and seccomp, with real commands you can run and compare.
- Metrics, Tracing and Dashboards for Containers Build container observability with cAdvisor, Prometheus, Grafana and OpenTelemetry: useful PromQL queries, app metrics, traces and a Compose stack to start from.
- Docker Model Runner, Extensions and Docker Debug Meet three Docker add-ons: Model Runner for local AI models and Compose models, Desktop Extensions, and docker debug for shells in slim or stopped containers.
Data and Volumes
- Container Storage Understand why data disappears when a container is removed, how the writable layer and copy-on-write work, and when to use volumes, bind mounts or tmpfs mounts.
- Volumes Master Docker volumes: docker volume create, ls, inspect, rm and prune, named versus anonymous volumes, -v versus --mount, sharing, read-only mounts and the volume lifecycle.
- Bind Mounts Share a host folder with a container using bind mounts: -v and --mount syntax, live code editing, read-only mounts, file ownership, and Windows and macOS path notes.
- tmpfs and In-Memory Storage Use Docker tmpfs mounts for fast, temporary, in-memory files: --tmpfs and --mount syntax, size limits, noexec, memory accounting, read-only containers and secrets.
- Backup and Restore Back up and restore Docker volumes with a helper container and tar, copy data between volumes and hosts, and use pg_dump for consistent database backups.
- Volume Drivers and Remote Storage Learn how Docker volume drivers work: local driver options for tmpfs, bind and NFS volumes, CIFS shares, third-party plugins, Compose driver_opts and performance notes.
Networking
- Docker Networking Understand Docker networking: the network drivers, how the default bridge connects containers, container IP addresses and gateways, outbound access, and DNS basics.
- Publishing Ports Learn every form of docker run -p, how host IP binding works, what -P and EXPOSE really do, how to debug unreachable ports, and why 0.0.0.0 exposes your service.
- User-Defined Bridge Networks Learn why you should create your own Docker bridge networks: automatic DNS by container name, isolation, network aliases, connect and disconnect, subnets and internal networks.
- Host, None, Macvlan and Overlay Understand every Docker network driver: bridge, host, none, macvlan, ipvlan and overlay. See when each one fits, the host networking caveats, and what overlay needs Swarm for.
- Containers Talking to Each Other Learn how containers connect: service names as hostnames, container ports versus published ports, the app-and-database pattern, tiered networks, and handling startup order.
- Troubleshooting Networks Debug Docker network problems like a pro: inspect networks, test DNS and ports from a helper container, spot loopback binds, port conflicts and wrong-network mistakes.
- DNS, Proxies and Firewalls Customize Docker container DNS with --dns and --add-host, reach the host via host.docker.internal, configure corporate proxies for builds and runs, and understand iptables.
Docker Compose
- Introduction to Docker Compose Start with Docker Compose: why it exists, how a compose.yaml describes services, what docker compose up and down do, project names, and why the version key is obsolete.
- Services in Compose Learn how to describe containers as Compose services: image vs. build, ports, command, entrypoint, environment, restart policies, depends_on, and how scaling works.
- Networks and Volumes in Compose Learn how Compose creates the default network, how to design front-end and back-end networks, and how named volumes, bind mounts, tmpfs and external resources behave.
- Environment, Variables and Secrets Understand the two kinds of variables in Compose: interpolation in the file and environment inside containers. Covers .env, env_file, precedence, profiles, secrets and configs.
- Startup Order and Health Stop 'connection refused' at startup: learn depends_on conditions, healthchecks, service_completed_successfully for migrations, up --wait, and restart policies in Compose.
- Compose for Development Set up a fast Compose dev loop: bind-mount your code, protect node_modules, use compose watch with sync and rebuild, run one-off commands, and avoid file-event pitfalls.
- Multiple Files, Profiles and Extends Split a Compose project across files: compose.override.yaml, -f merging rules, !reset and !override, include, extends, YAML anchors, and when to choose each technique.
- Compose Commands A practical tour of the docker compose commands you use every day: up, down, ps, logs, exec, run, build, pull, config, scale, cp and top, with real output.
- Project: A Full-Stack App with Compose Build a four-service stack with Compose: nginx, a Python API, PostgreSQL and Redis, with healthchecks, networks, a named volume and a .env file. Every step tested.
Security
- Container Security Basics Understand what a container really isolates, what it shares with the host, the Docker defaults that protect you, and the threat model every Docker user should know.
- Non-Root Users and Capabilities Run containers as non-root, drop Linux capabilities with --cap-drop, add back only what you need, block privilege escalation, and know why --privileged is dangerous.
- Image Security and Scanning Keep Docker images safe: choose minimal bases, pin by digest, generate an SBOM with BuildKit, scan for vulnerabilities and verify signatures with Cosign.
- Managing Secrets Keep passwords and API keys out of images and logs: why ENV and ARG leak, how BuildKit secret mounts and Compose secrets work, runtime injection and rotation.
- seccomp, AppArmor and Read-Only Filesystems Lock down containers with seccomp profiles, AppArmor, read-only root filesystems, tmpfs and user namespaces. Real commands, real output and a hardened Compose file.
- Securing the Docker Daemon Why access to the Docker socket equals root on the host, how to protect the daemon with groups, TLS and SSH, why you should never mount the socket, and rootless Docker.
- A Container Security Checklist A practical Docker security checklist for the build, ship and run stages, with commands that verify each item and a small audit script you can run on any container.
- Docker Scout, SBOMs and Provenance Attach SBOM and SLSA provenance attestations to images with BuildKit, read them with imagetools, and use Docker Scout for vulnerability policies and supply chain checks.
Registries and CI/CD
- Working with Registries Learn how Docker registries work, how to read their names and auth flow, and how to log in safely to Docker Hub, GitHub, AWS, Google and Azure with credential helpers.
- Running a Private Registry Run your own Docker registry with the registry:2 image: push and pull, query the API, delete images, garbage-collect, add TLS and password auth, and know when not to.
- Tagging and Versioning Strategies Choose a Docker tag strategy that makes rollbacks safe: semantic versions, rolling tags, git SHA tags, immutable tags, promotion between registries and why latest hurts.
- Docker in CI Build, test and push Docker images from CI: test stages, tags from the commit SHA, registry layer caching, matrix builds, and GitHub Actions and GitLab CI examples.
- Build Performance Make Docker builds faster: measure first, shrink the build context, use cache mounts, run stages in parallel, share a remote cache and avoid common slowdowns.
- Deploying on a Single Host Run Docker Compose in production on one server: restart policies, health checks, a reverse proxy, TLS, resource limits, log rotation, updates and rollbacks.
- Docker Hub: Repositories, Automated Builds and Organizations Use Docker Hub well: repositories and tags, official and verified images, organizations and teams, access tokens, pull rate limits, webhooks and automated builds.
- Testing Images and Integration Tests with Containers Test the image you ship, not only the code: container-structure-test checks, smoke tests with Compose in CI, and the Testcontainers idea of throwaway dependencies.
Language Recipes
- Containerizing a Node.js App Containerize a Node.js app the right way: a multi-stage Dockerfile with npm ci, a non-root user, a healthcheck, graceful shutdown and production settings.
- Containerizing a Python App Containerize a Python web app: slim images, a virtual environment copied between stages, gunicorn, bytecode and buffering settings, uv, a healthcheck and non-root.
- Containerizing a Java App Containerize a Java app with a multi-stage build, a JRE runtime image, correct JVM memory flags, Maven and Gradle caching, Spring Boot layers and jlink.
- Containerizing Go and Rust Apps Containerize Go and Rust apps with multi-stage builds: static binaries, scratch and distroless images, module and crate caching, cross compilation, and pitfalls.
- Containerizing a PHP App Containerize a PHP application with Docker: php-fpm plus nginx in Compose, Composer in a build stage, OPcache settings, extensions, non-root users and Laravel tips.
- Containerizing a .NET App Containerize an ASP.NET Core app with Docker: SDK and runtime images, dotnet publish, restore caching, ASPNETCORE_HTTP_PORTS, non-root users and chiseled images.
- Running Databases in Containers Run PostgreSQL, MySQL and Redis in Docker: persistent volumes, init scripts, credentials, healthchecks, backups with pg_dump and mysqldump, and when not to use containers.
- Nginx and Reverse Proxies Run nginx in Docker as a static file server and reverse proxy: config mounts, templates, proxy_pass pitfalls, TLS termination, health checks, plus Caddy and Traefik.
- Running Dev Tools in Containers: Jenkins, Gitea, Portainer, Pi-hole Run Jenkins, Gitea, Portainer and Pi-hole in Docker: volumes for state, ports, the Docker socket risk, a custom Jenkins image with plugins and a DNS container.
Orchestration Basics
- Why Orchestration? Understand why running containers at scale needs orchestration: scaling, self-healing, rolling updates and service discovery, with hands-on Docker and Compose limits.
- Docker Swarm Basics Learn how Docker Swarm turns several machines into one cluster: manager and worker nodes, services, replicas, stacks, rolling updates and rollbacks.
- From Docker to Kubernetes A Docker user's guide to Kubernetes: pods, deployments, services and config objects, how each maps to Docker and Compose concepts, and the kubectl basics.
- Logging and Monitoring How Docker collects container logs, logging drivers, json-file rotation, centralized logging, and basic metrics with docker stats, events, cAdvisor and Prometheus.
- Docker in Docker and Socket Access How to run docker commands from inside a container: Docker-in-Docker, mounting the socket, remote daemons, rootless builders and Testcontainers, with their risks.
- Dev Containers and Remote Development Use containers as your development environment: devcontainer.json, building a dev image, bind-mounted workspaces, Compose-based setups, and VS Code or Codespaces.
- Swarm Services, Stacks and Rolling Updates Go deeper into Docker Swarm: service modes, stack files with deploy settings, rolling updates and rollbacks, secrets, configs, and how to rotate them safely.
- Swarm Nodes, Overlay Routing Mesh and Managing Clusters Manage a Docker Swarm cluster: manager quorum, promoting and draining nodes, labels, autolock, backups, the ingress routing mesh and overlay networks.
Projects
- Project: Serve a Static Site Build and ship a static website with Docker: run nginx with a bind mount, add a custom config, bake everything into an image with a healthcheck, and use Compose.
- Project: A Node.js API with a Database Containerize a Node.js API with PostgreSQL: multi-stage Dockerfile, Compose, named volume, healthchecks and SQL migrations run as a one-off container.
- Project: A Python App with Redis Build a Python web app and a background worker that share a Redis queue, run both from one image with Compose, scale workers and stop them gracefully.
- Project: A Message Queue with RabbitMQ and Compose Build a producer and scalable workers around RabbitMQ with Docker Compose: health-gated startup, durable queues, acknowledgements, graceful shutdown and scaling.
- Project: Multiple Apps Behind a Proxy Put one nginx reverse proxy in front of several containers: path-based and host-based routing, forwarded headers, DNS pitfalls, plus the same setup in Caddy.
- Project: A Tiny Go Image Shrink a Go web service from 453 MB to 9 MB with a multi-stage build and a scratch image, then fix certificates, compare bases and harden the container.
- Project: A Build and Release Pipeline Build a complete Docker release pipeline: run tests in a build stage, tag by version and commit, smoke test, push to a registry, deploy and roll back by tag.
Practice
- Docker Cheat Sheet One-page Docker cheat sheet: commands grouped by task, Dockerfile instructions, Compose keys, format strings, exit codes and safe clean-up. Tested on Docker 29.
- Common Docker Errors Port already allocated, name conflicts, exec format error, permission denied, no space left, failed builds and Compose mistakes: real error text, causes and fixes.
- Choosing Your Deployment Path A practical guide to running Docker in production: one host with Compose, Swarm, managed container services, Kubernetes or serverless containers, and how to decide.
- Docker Interview Questions Forty Docker interview questions with clear, verified answers on images, containers, Dockerfiles, networking, volumes, Compose and security, plus tips for answering.
- Practice: Debugging a Broken Compose Stack Hands-on exercise: fix a Compose stack with six planted bugs (undefined volume, wrong env name, localhost, port mapping, startup race, health check) step by step.