beginner devops Docker 26 · Updated April 2026

Docker Essentials Cheatsheet

Master Docker fundamentals with this comprehensive cheatsheet, covering core concepts, essential commands, and practical patterns for containerization.

· 8 min read · AI-reviewed
-->

Quick Overview

Docker is an open-source platform that enables developers to build, ship, and run applications in isolated environments called containers. It simplifies the deployment process by packaging an application and its dependencies into a single unit, ensuring consistency across various computing environments. You’ll reach for Docker to streamline development workflows, create reproducible build environments, and deploy scalable microservices. This guide covers Docker Engine version 26.

One-Line Install (Linux convenience script):

# This script is for convenience/testing only. For production, follow official docs.
curl -fsSL https://get.docker.com | sh

Getting Started

Let’s get Docker up and running on your machine and run your first container.

Installation

Docker Desktop is the easiest way to get started on Windows and macOS, bundling Docker Engine, Docker CLI, Docker Compose, and a GUI. On Linux, you’ll typically install Docker Engine directly.

Hello World

Verify your installation by running a simple container:

# Pulls the "hello-world" image and runs it as a container
docker run hello-world

You should see a message confirming Docker is working correctly.

Core Concepts

Understanding these fundamental concepts is key to mastering Docker:

ConceptDescription
ImageA read-only, executable package that includes everything needed to run an application: code, runtime, libraries, environment variables, and configuration files. Images are built from a Dockerfile.
ContainerA runnable instance of an image. You can create, start, stop, move, or delete a container. Each container is isolated from other containers and the host system.
DockerfileA text file containing a sequence of instructions that Docker uses to build an image. It defines the application’s environment, dependencies, and how it should be run.
RegistryA service for storing and retrieving Docker images. Docker Hub is the default public registry. You can also run private registries.
VolumeA mechanism for persisting data generated by and used by Docker containers. Volumes allow data to outlive a container’s lifecycle and be shared between containers.
NetworkEnables communication between Docker containers and between containers and the host. Docker provides different network drivers for various use cases.
ComposeA tool (docker compose) for defining and running multi-container Docker applications. It uses a YAML file (e.g., docker-compose.yml) to configure all services, networks, and volumes for an application, then spins them up with a single command.

Essential Commands / API / Syntax

The 80/20 of Docker commands you’ll use daily.

Images

Images are the blueprints for your containers.

Containers

Containers are running instances of images.

Volumes

Manage persistent data for your containers.

Networks

Connect containers to each other.

Common Patterns

Real-world scenarios for using Docker effectively.

1. Building a Custom Web Application Image

This pattern demonstrates how to containerize a simple web application using a Dockerfile.

Dockerfile Example:

# Use a lightweight Node.js base image (version 20 for Alpine Linux)
FROM node:20-alpine

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to install dependencies
# We copy these first to leverage Docker's build cache
COPY package*.json ./

# Install application dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Expose the port the application listens on
EXPOSE 3000

# Define the command to run the application when the container starts
CMD ["npm", "start"]

To build and run:

# Build the image, tagging it as 'my-node-app:latest'
docker build -t my-node-app:latest .

# Run the application, mapping host port 80 to container port 3000
# and name the container 'node-frontend'
docker run -d -p 80:3000 --name node-frontend my-node-app:latest

2. Orchestrating Multi-Container Applications with docker compose

For applications with multiple services (e.g., a web server, a database, a cache), docker compose simplifies management. As of Docker 26, docker compose is integrated directly into the Docker CLI (note the space, not a hyphen, for version 2 and later).

docker-compose.yml Example:

# Specify the Compose file format version (current best practice is to omit,
# as Compose v2/v5 rely on the Compose Specification)
# See: https://docs.docker.com/compose/compose-file/
services:
  web:
    build: . # Build from the Dockerfile in the current directory
    ports:
      - "80:80" # Map host port 80 to container port 80
    volumes:
      - ./app:/app # Mount local './app' directory into container's /app
    depends_on:
      - db # Ensure 'db' service starts before 'web'
    environment:
      DATABASE_HOST: db # Set an environment variable for the web service
      DATABASE_PORT: 5432
  db:
    image: postgres:15 # Use an official PostgreSQL image
    environment:
      POSTGRES_DB: mydatabase
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
    volumes:
      - db-data:/var/lib/postgresql/data # Persist database data in a named volume

volumes:
  db-data: # Define the named volume

To run the application:

# Start all services defined in docker-compose.yml in detached mode
docker compose up -d

# Stop and remove containers, networks, and volumes (if specified)
docker compose down

3. Cleaning Up Docker Resources

Over time, unused images, containers, and volumes can accumulate.

# Remove all stopped containers
docker container prune

# Remove all dangling (unused) images
docker image prune

# Remove all dangling (unused) volumes
docker volume prune

# Remove all unused networks
docker network prune

# Remove all unused Docker objects (containers, images, volumes, networks)
# Use with caution!
docker system prune -a

Gotchas & Tips

Things that often trip up developers when working with Docker.

Next Steps


Source: z2h.fyi/cheatsheets/docker-essentials — Zero to Hero cheatsheets for developers.