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.
- 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
| Resource | URL | Purpose |
|---|---|---|
| Official website | www.docker.com | Product information, Docker Desktop downloads, and pricing plans |
| Official documentation | docs.docker.com | Complete reference for commands and configuration |
| Installation instructions | Get Docker | Official installation steps for each operating system |
| Docker Hub | hub.docker.com | Search for and download images, and push your own images |
| Docker Engine source code | github.com/moby/moby | Docker Engine's open-source project (Moby) |
| Docker CLI source code | github.com/docker/cli | Source code for the docker command |
| Docker Compose source code | github.com/docker/compose | Source code and releases for docker compose |
| Release notes | Engine, Desktop | New 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.
| Software | Version tested in this tutorial | Minimum requirements and notes |
|---|---|---|
| Docker Engine | 29.9.0 | Version 25 or later is recommended. Most commands still work on older versions, but some output formats differ |
| Docker Compose | v5.6.0 | Uses 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 Buildx | v0.38.0 | Docker Engine uses BuildKit by default for builds starting with version 23; syntax such as RUN --mount requires BuildKit |
| Docker Desktop (Windows, macOS) | 4.95 | Includes 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
| System | Requirements |
|---|---|
| Windows | 64-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 |
| macOS | One of the three latest major macOS versions; Apple Silicon or Intel; at least 4 GB of memory |
| Linux | This 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
| Image | Version | Used for |
|---|---|---|
nginx | 1.30 (stable) | Web server, reverse proxy |
node | 24 (LTS) | Node.js examples |
python | 3.14 | Python examples |
postgres | 18 | PostgreSQL database |
mysql | 8.4 (LTS) | MySQL, WordPress |
redis | 8 | Redis cache |
wordpress | 7 | WordPress projects |
alpine / ubuntu | 3.23 / 26.04 | Base images for exercises |
caddy | 2 | Automatic HTTPS reverse proxy, deployment |
golang + distroless/static-debian13 | 1.27 | Multi-stage builds, multi-platform images |
registry | 3 | Local Registry (push exercises) |
phpmyadmin / adminer | latest | Database 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 runand 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
- What is Docker
Learn what Docker is, how it solves environment differences, and how images, containers, registries, Docker Engine, and virtual machines fit together.
- 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.
- 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.
- 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.
- Images
Learn Docker image names, tags, and digests, then use pull, images, tag, rmi, history, inspect, save, and load. Compare image sizes and layers.
- 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.
- 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.
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
- 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.
- 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.
- 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
- 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.
- 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.
- 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.
- 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
- Python apps
Package Python apps as Docker images with tested Flask, FastAPI, and Django examples, development reload, collectstatic, uv locks, and image size comparisons.
- 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.
- 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.
- 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.
- 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.
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- docker network
A complete guide to the docker network create, ls, inspect, connect, disconnect, rm, and prune commands, with examples tested on Docker 29.
- docker compose up
Learn `docker compose up` options including `--build`, `--wait`, `--scale`, and `--exit-code-from`, with practical Docker Compose v5 examples.
- 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