Docker Commands Cheatsheet: 40 Essential Commands for 2026

A comprehensive reference for every Docker command you actually use in day-to-day development. Bookmark this page.

Container Lifecycle

1. docker run

Create and start a container from an image. The most fundamental Docker command.

# Run interactively with a TTY
docker run -it ubuntu:22.04 bash

# Run detached, map port 3000 on host to 80 in container
docker run -d -p 3000:80 --name my-app nginx

# Run with environment variables and auto-remove on exit
docker run --rm -e NODE_ENV=production -p 8080:8080 my-node-app

2. docker create

Create a container without starting it. Useful for pre-configuring before launch.

docker create --name my-container -p 5000:5000 flask-app
docker start my-container

3. docker start / stop / restart

Control the lifecycle of existing containers.

docker start my-app
docker stop my-app          # Graceful SIGTERM, then SIGKILL after 10s
docker stop -t 30 my-app    # Wait 30s before SIGKILL
docker restart my-app

4. docker rm

Remove stopped containers.

docker rm my-app
docker rm -f my-app         # Force-remove even if running
docker rm $(docker ps -aq)  # Remove ALL stopped containers

5. docker kill

Send a signal to a running container. Default is SIGKILL.

docker kill my-app
docker kill --signal=SIGHUP my-app

6. docker pause / unpause

Freeze and unfreeze a running container without stopping it.

docker pause my-app
docker unpause my-app

Container Inspection & Debugging

7. docker ps

List running containers. Add -a for all (including stopped).

docker ps
docker ps -a
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

8. docker logs

View container stdout/stderr. Essential for debugging.

docker logs my-app
docker logs -f my-app          # Follow (tail -f)
docker logs --tail 50 my-app   # Last 50 lines
docker logs --since 1h my-app  # Last hour only

9. docker exec

Run a command inside a running container.

# Open a shell inside the container
docker exec -it my-app bash
docker exec -it my-app sh      # For Alpine-based images

# Run a one-off command
docker exec my-app cat /etc/hosts

10. docker inspect

Detailed JSON metadata about a container or image.

docker inspect my-app
docker inspect --format '{{.NetworkSettings.IPAddress}}' my-app
docker inspect --format '{{json .Config.Env}}' my-app | jq

11. docker top

Show running processes inside a container.

docker top my-app

12. docker stats

Live resource usage (CPU, memory, network I/O) for containers.

docker stats
docker stats my-app --no-stream   # One-time snapshot

13. docker diff

Show filesystem changes made in a container since it was created.

docker diff my-app
# A = added, C = changed, D = deleted

Image Management

14. docker build

Build an image from a Dockerfile.

docker build -t my-app:latest .
docker build -t my-app:v2 -f Dockerfile.prod .
docker build --no-cache -t my-app:latest .
docker build --build-arg NODE_VERSION=20 -t my-app .

15. docker images / docker image ls

List local images.

docker images
docker images --filter "dangling=true"   # Untagged images
docker images --format "{{.Repository}}:{{.Tag}} {{.Size}}"

16. docker pull / push

Download or upload images from/to a registry.

docker pull node:20-alpine
docker push myregistry.io/my-app:latest

17. docker tag

Create a new tag for an existing image.

docker tag my-app:latest myregistry.io/my-app:v1.2.3

18. docker rmi

Remove images.

docker rmi my-app:old
docker rmi $(docker images -q --filter "dangling=true")  # Remove dangling

19. docker history

Show the layers of an image and their sizes. Great for optimizing builds.

docker history my-app:latest
docker history --no-trunc my-app:latest

20. docker save / load

Export and import images as tar archives (for offline transfer).

docker save my-app:latest -o my-app.tar
docker load -i my-app.tar

Volumes & Data

21. docker volume create

Create a named volume for persistent data.

docker volume create pgdata

22. docker volume ls

List all volumes.

docker volume ls
docker volume ls --filter "dangling=true"

23. docker volume inspect

Show details about a volume, including its mount point on the host.

docker volume inspect pgdata

24. docker volume rm / prune

Remove unused volumes.

docker volume rm pgdata
docker volume prune          # Remove ALL unused volumes

25. Mounting volumes in docker run

There are two ways to mount data into containers:

# Named volume (Docker-managed)
docker run -v pgdata:/var/lib/postgresql/data postgres

# Bind mount (host directory)
docker run -v $(pwd)/src:/app/src my-app

# Read-only mount
docker run -v $(pwd)/config:/app/config:ro my-app

Networking

26. docker network create

Create a custom network so containers can communicate by name.

docker network create my-network
docker network create --driver bridge --subnet 172.20.0.0/16 my-network

27. docker network ls

List all Docker networks.

docker network ls

28. docker network connect / disconnect

Attach or detach a running container from a network.

docker network connect my-network my-app
docker network disconnect my-network my-app

29. docker network inspect

Show all containers on a network, their IPs, and configuration.

docker network inspect my-network

30. Running containers on a shared network

Containers on the same network can reach each other by container name.

docker network create app-net
docker run -d --name db --network app-net postgres
docker run -d --name api --network app-net -e DB_HOST=db my-api
# "api" can connect to postgres at hostname "db"

Docker Compose

31. docker compose up

Start all services defined in compose.yaml.

docker compose up
docker compose up -d             # Detached
docker compose up --build        # Rebuild images first
docker compose up -d --scale worker=3

32. docker compose down

Stop and remove containers, networks, and optionally volumes.

docker compose down
docker compose down -v           # Also remove volumes
docker compose down --rmi all    # Also remove images

33. docker compose logs

View logs from all services, or a specific one.

docker compose logs
docker compose logs -f api       # Follow logs for "api" service

34. docker compose exec

Run a command in a running Compose service.

docker compose exec db psql -U postgres
docker compose exec api sh

35. docker compose ps

Show status of Compose services.

docker compose ps

36. docker compose build

Build or rebuild images without starting containers.

docker compose build
docker compose build --no-cache api

System & Cleanup

37. docker system df

Show Docker disk usage — images, containers, volumes, and build cache.

docker system df
docker system df -v   # Verbose breakdown

38. docker system prune

The nuclear option for reclaiming disk space.

docker system prune              # Remove unused containers, networks, dangling images
docker system prune -a            # Also remove unused images (not just dangling)
docker system prune -a --volumes  # Also remove unused volumes

39. docker cp

Copy files between a container and the host.

docker cp my-app:/app/logs/error.log ./error.log
docker cp ./config.json my-app:/app/config.json

40. docker login / logout

Authenticate to a container registry.

docker login
docker login ghcr.io
docker logout

Bonus: Common Dockerfile Patterns

A good cheatsheet isn't complete without the Dockerfile itself. Here are two production-ready patterns:

Multi-stage Node.js build

# Stage 1: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Stage 2: Production
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]

Python with non-root user

FROM python:3.12-slim
RUN groupadd -r appuser && useradd -r -g appuser appuser
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
USER appuser
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:8000"]

Quick Reference Table

TaskCommand
Run a containerdocker run -d -p 8080:80 image
Shell into containerdocker exec -it name bash
View logsdocker logs -f name
Stop everythingdocker compose down
Reclaim disk spacedocker system prune -a
Check resource usagedocker stats

Level Up Your Workflow

Use our free developer tools to format JSON responses from Docker APIs, encode environment variables, or decode JWTs from your containerized services.