Contents

Docker tutorial: Get started with containers, images, and Compose

Docker is a tool that packages an application together with everything it needs (runtime, libraries, and settings). The packaged item is called an image, and when you run it, it becomes a container. The same image runs the same way on your laptop, a coworker's computer, or a cloud server.

Docker whale logo
Docker
Developer
Docker, Inc.
First released
2013
Developed in
Go
License
Docker Engine is open-source software (Apache License 2.0); Docker Desktop is commercial software and free for individuals and small businesses
Official website
www.docker.com
Official documentation
docs.docker.com

This Docker tutorial starts with the basics and takes you all the way to writing your own Dockerfile, managing multiple services with Docker Compose, and deploying a website to a cloud host.

Official resources

ResourceURLPurpose
Official websitewww.docker.comProduct information, Docker Desktop downloads, and pricing plans
Official documentationdocs.docker.comComplete reference for commands and configuration
Installation instructionsGet DockerOfficial installation steps for each operating system
Docker Hubhub.docker.comSearch for and download images, and push your own images
Docker Engine source codegithub.com/moby/mobyDocker Engine's open-source project (Moby)
Docker CLI source codegithub.com/docker/cliSource code for the docker command
Docker Compose source codegithub.com/docker/composeSource code and releases for docker compose
Release notesEngine, DesktopNew features and changes in each release

Docker and the whale logo are trademarks of Docker, Inc. This tutorial is an unofficial learning resource and is not affiliated with Docker, Inc.

Versions used in this tutorial

Every command in this tutorial was run in October 2026. The terminal blocks with a black background show real command output (with only unrelated content, such as download progress, removed). Values such as container IDs, times, and file sizes will differ in your output. That is normal.

SoftwareVersion tested in this tutorialMinimum requirements and notes
Docker Engine29.9.0Version 25 or later is recommended. Most commands still work on older versions, but some output formats differ
Docker Composev5.6.0Uses docker compose (the plugin version). Version 2.20 or later can run this tutorial's compose.yaml; the old docker-compose (v1) is no longer maintained
Docker Buildxv0.38.0Docker Engine uses BuildKit by default for builds starting with version 23; syntax such as RUN --mount requires BuildKit
Docker Desktop (Windows, macOS)4.95Includes Docker Engine and Compose; see system requirements below

Compose's version number jumps directly from v2 to v5 (skipping v3 and v4 to avoid confusion with the old Compose file formats “version 2 / 3”). The commands work the same way as in v2.

System requirements

SystemRequirements
Windows64-bit Windows 10 22H2 (build 19045) or Windows 11 23H2 (build 22631) or later; WSL 2.1.5 or later and virtualization enabled in the BIOS; at least 8 GB of memory
macOSOne of the three latest major macOS versions; Apple Silicon or Intel; at least 4 GB of memory
LinuxThis tutorial uses Ubuntu (24.04 / 26.04), x86_64 or arm64; Docker Engine can also be installed on other major distributions

Image versions used in examples

ImageVersionUsed for
nginx1.30 (stable)Web server, reverse proxy
node24 (LTS)Node.js examples
python3.14Python examples
postgres18PostgreSQL database
mysql8.4 (LTS)MySQL, WordPress
redis8Redis cache
wordpress7WordPress projects
alpine / ubuntu3.23 / 26.04Base images for exercises
caddy2Automatic HTTPS reverse proxy, deployment
golang + distroless/static-debian131.27Multi-stage builds, multi-platform images
registry3Local Registry (push exercises)
phpmyadmin / adminerlatestDatabase management interfaces

Examples use fixed versions wherever possible (for example, postgres:18), so following along will give you the same results as in the tutorial.

What you'll learn

  • How Docker, images, and containers relate to one another
  • How to install Docker on Windows, macOS, and Linux
  • How to run containers with docker run and manage their lifecycle
  • How to write a Dockerfile and package your own application as an image
  • How to persist data with volumes and connect containers over a network
  • How to start multiple services at once with Docker Compose
  • How to run Python, Node.js, Nginx, MySQL, PostgreSQL, Redis, and WordPress with Docker
  • How to clean up space, configure security, use Rootless and Podman, and work with multi-platform images
  • How to use GitHub Actions to build automatically and deploy to a cloud host
  • How Docker works under the hood (namespace, cgroup, overlayfs)
  • How to find the cause of an error in the Common error messages guide; for full options for common commands, see “Command reference”

Who this is for

  • Developers trying Docker for the first time
  • Teams that often run into “it works on my machine” problems
  • People who want to deploy a project to the cloud without configuring a server by hand

If you can enter commands in a terminal (command line), you can get started. You don't need to know Linux or server administration first.

How to read this tutorial

  • Code blocks with a white background contain commands to enter or file contents. Click “Copy” in the upper-right corner to copy them.
  • Blocks with a black background labeled Terminal show command output. The line starting with $ is the command you entered, followed by its output; clicking “Copy” copies only the command.
  • For commands with Linux / macOS, Windows PowerShell, and Windows CMD tabs, select your operating system. The whole page will switch to the matching syntax.
  • Each chapter starts with an estimated time, prerequisite chapters, and learning objectives. At the end, you'll find a Recap, Exercises with answers, and Frequently asked questions.
  • The web pages shown in screenshots were captured after running them. Some screenshots of Docker Desktop and Docker Hub interfaces come from the official Docker documentation (Apache License 2.0); the captions identify them.

Quickstart

After installing Docker, enter this in a terminal:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
4f55086f7dd0: Pull complete
Digest: sha256:5e23090353324d887c48ad5e5c56d294eab81588df9605b07d1afe895f9cc8f8
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Seeing Hello from Docker! means everything is working. Next, start with What is Docker.

FAQ

Is this tutorial suitable for people who have never used Docker?

Yes. It starts with installation and your first container, and includes real output at every step so you can follow along and get the same results.

Can I use the commands in this tutorial on Windows?

Yes. Where different syntax is needed (such as the $(pwd) path), you'll find tabs for Linux/macOS, PowerShell, and CMD. You can also use Linux syntax directly in WSL.

Can I download the example code?

The “Example code” link at the start of each chapter opens that chapter's complete project.

Getting started

  1. What is Docker

    Learn what Docker is, how it solves environment differences, and how images, containers, registries, Docker Engine, and virtual machines fit together.

  2. Install Docker

    Install Docker on Windows with WSL 2, macOS, and Linux (Ubuntu 26.04 / 24.04). Verify virtualization and WSL, then test with docker version and hello-world.

  3. Docker Desktop interface tour

    A screen-by-screen tour of Docker Desktop, from the sidebar and container controls to logs, files, Compose projects, images, and the Docker commands behind each action.

  4. Your first container

    Run your first Docker container with nginx: pull an image with docker run, open it in a browser, inspect it with ps, logs, and exec, and manage it with stop, start, and rm.

  5. Images

    Learn Docker image names, tags, and digests, then use pull, images, tag, rmi, history, inspect, save, and load. Compare image sizes and layers.

  6. Container lifecycle

    Learn Docker container states, why containers exit, stop vs. kill, the 10-second stop timeout, exit codes, and restart policies with real output.

  7. docker run flags

    Learn the most useful docker run flags: -d, -it, -p, -v, -e, --name, --rm, --network, --restart, resource limits, and more, with real commands and output.

  8. View logs and debug

    Learn to debug Docker containers with logs, exec, inspect, cp, stats, top, and diff, and troubleshoot common startup, port, and exec format errors.

Images and Dockerfile

  1. Dockerfile basics

    Learn to write a Dockerfile with a Node.js example. Read docker build output, understand each instruction and build cache, and use .dockerignore to shrink the build context from 30 MB to under 1 KB.

  2. Generate files with docker init

    Use docker init to answer a few questions and generate a Dockerfile, compose.yaml, .dockerignore, and README.Docker.md. See the full Node.js walkthrough, review each generated file, use docker build --check to find two template warnings, and learn where the PostgreSQL example fails with postgres:18.

  3. Dockerfile instructions

    Learn the most common Dockerfile instructions and see them in action: FROM, RUN, COPY, ADD, WORKDIR, ENV, ARG, EXPOSE, USER, VOLUME, HEALTHCHECK, CMD, and ENTRYPOINT. Compare CMD and ENTRYPOINT, COPY and ADD, ARG and ENV, and see how PID 1 affects docker stop.

  4. Build Cache and Optimization

    Learn Docker build cache rules, how instruction order affects build time, how to reduce image size by cleaning in the same layer, and how to use cache mounts and clear the build cache.

  5. Multi-stage builds

    Separate build and runtime environments with multi-stage builds. Compare Go image sizes and explore Dockerfile examples for Node.js, Java, and frontend apps.

  6. Push to Docker Hub

    Learn docker login, docker tag, and docker push to upload images to Docker Hub and GitHub Container Registry, and run a private Registry with registry:3.

Data and networking

  1. Volumes and data persistence

    Keep data after containers are removed. Learn Docker volumes, bind mounts, anonymous volumes, backup and restore, path behavior, and the PostgreSQL 18 data directory.

  2. Networking and container communication

    Learn how Docker networking works, connect containers by name on custom networks, publish ports, reach the host, and troubleshoot common connection issues.

  3. Environment variables and .env

    Learn -e, --env-file, Dockerfile ENV, and Compose environment, env_file, and .env substitution with real output, plus safe ways to pass secrets.

Docker Compose

  1. Docker Compose Tutorial

    Get started with Docker Compose: launch a website, PostgreSQL, and Adminer with one compose.yaml file. See real output for up, ps, logs, stop, and down, plus Adminer login, SQL, and how down -v affects data.

  2. compose.yaml syntax

    Learn the complete syntax of Docker Compose's compose.yaml file, including services, builds, ports, volumes, health checks, profiles, overrides, and validation.

  3. Docker Compose commands

    A practical guide to Docker Compose commands: up, down, ps, logs, exec, run, pull, and config. See why restart does not apply compose.yaml changes and when to use up -d.

  4. Build a WordPress Site

    Set up WordPress 7 and MySQL 8.4 with Docker Compose. Configure health checks, persistent data, upload limits, phpMyAdmin, backups, restores, and image updates.

Real-world examples

  1. Python apps

    Package Python apps as Docker images with tested Flask, FastAPI, and Django examples, development reload, collectstatic, uv locks, and image size comparisons.

  2. Node.js apps

    Build Node.js images with Docker: use npm ci, run as a non-root user, handle SIGTERM, build TypeScript apps, slim Next.js images, and reload code during development.

  3. Nginx and reverse proxying

    Serve static sites with Nginx in Docker, configure SPA fallbacks and caching, validate config, proxy to backend containers, troubleshoot 502 errors, and enable HTTPS with Caddy.

  4. MySQL

    Run MySQL 8.4 in Docker with real output: environment variables, init SQL, utf8mb4, connecting from the container, host and other containers, localhost vs 127.0.0.1, the Compose health check trap, mysqldump backup and restore, and why a changed password variable has no effect.

  5. PostgreSQL

    Run PostgreSQL 18 in Docker with real output: its new data directory, Compose setup, pg_isready health check, psql commands, passwordless container access, backups, restores, and a 16-to-18 upgrade.

  6. Redis

    Run Redis 8 with Docker: use redis-cli, configure passwords, compare RDB and AOF persistence, test memory eviction, and connect a Flask app with Compose.

Operations and advanced topics

  1. Reclaim disk space

    Is Docker using too much disk space? Find out with docker system df, then safely clean up containers, images, volumes, builder cache, and logs.

  2. Security best practices

    Learn Docker container security with hands-on examples: run as non-root, pin image versions, keep secrets out of layers, use BuildKit secrets, restrict ports and privileges, set resource limits, protect docker.sock, and scan and patch vulnerabilities with Trivy.

  3. Rootless and Podman

    See how Rootless Docker maps container root to an unprivileged host user, blocks access to /etc/shadow, and compare it with daemonless Podman.

  4. Multi-platform images

    Image built on an Apple Silicon Mac fails on a server with exec format error? Learn CPU architectures and multi-platform images, build linux/amd64 and linux/arm64 at once with docker buildx and Go cross-compilation, inspect with docker images --tree, push and check the manifest, and know when you need QEMU.

  5. Build automatically with GitHub Actions

    Automatically build multi-platform Docker images and push them to GitHub Container Registry, then deploy to a server over SSH. Includes a complete workflow, tag rules, build cache, and actionlint validation.

  6. Deploy to a cloud server

    Deploy a Docker app to a Linux cloud server with a complete walkthrough: build and push an image, run it with Compose, update and roll back, automate backups, and review a launch checklist.

  7. Internals

    See what a container is on a Docker host: a Linux process isolated by namespaces, limited by cgroups, and given a filesystem by overlayfs. Inspect PIDs, resource limits, image layers, and security controls.

  8. Common error messages

    Find the cause of Docker errors like daemon connection failures, permission denied, port conflicts, missing files, Compose health checks, and PowerShell issues, with real output and fixes.

  9. Docker command cheat sheet

    A one-page guide to the Docker commands you use most: containers, images, builds, volumes, networks, Compose, cleanup, and system info, with concise explanations.

Command reference

  1. docker build

    A complete guide to docker build options (-t, -f, --build-arg, --target, --no-cache, --pull, --platform, --progress, --secret, --check, -q, and more), with Docker 29 examples for naming images, passing build arguments, choosing a Dockerfile, building to a stage, and viewing full build output.

  2. docker exec

    Learn every docker exec option, including -it, -u, -w, -e, -d, --env-file, and --privileged. Examples cover shells, users, directories, environment variables, background tasks, and stopped containers.

  3. docker ps

    Learn docker ps options: list all containers, filter by status, name, or label, customize output, show sizes, and remove stopped containers. Includes Docker 29 examples.

  4. docker logs

    A complete guide to docker logs options (-f, -n/--tail, -t, --since, --until, --details), with Docker 29 examples for filtering, timestamps, stdout and stderr, grep, and following new logs.

  5. docker cp

    Learn docker cp syntax and how to copy files and folders between containers and hosts, handle missing files, and back up or restore databases on Windows.

  6. docker inspect

    Learn Docker inspect options and Go templates with real Docker 29 examples for container state, IPs, environment variables, image details, volumes, networks, and the removed IPAddress field.

  7. docker volume

    A complete guide to docker volume create, ls, inspect, rm, and prune, with hands-on Docker 29 examples for writing data, finding dangling anonymous volumes, labels, and prune versus prune -a.

  8. docker network

    A complete guide to the docker network create, ls, inspect, connect, disconnect, rm, and prune commands, with examples tested on Docker 29.

  9. docker compose up

    Learn `docker compose up` options including `--build`, `--wait`, `--scale`, and `--exit-code-from`, with practical Docker Compose v5 examples.

  10. docker compose down

    Learn docker compose down options, including -v, --rmi, --remove-orphans, and --timeout, with examples and the differences between down, stop, and rm.

Updated October 14, 2026