AI Generate Docker docs instantly

Docker Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Images

6 snippets

Build and manage images

List Images

docker images
docker image ls

Pull Image

docker pull nginx
docker pull nginx:1.25

Build Image

docker build -t myapp:1.0 .
docker build -f Dockerfile.dev -t myapp:dev .

Remove Image

docker rmi nginx
docker rmi $(docker images -q)  # All images

Tag Image

docker tag myapp:1.0 registry.com/myapp:1.0

Push Image

docker push registry.com/myapp:1.0

Containers

6 snippets

Run and manage containers

Run Container

docker run nginx
docker run -d nginx           # Detached
docker run -it ubuntu bash    # Interactive

Run with Options

docker run -d \
  --name web \
  -p 8080:80 \
  -v ./html:/usr/share/nginx/html \
  -e ENV_VAR=value \
  nginx

List Containers

docker ps                     # Running
docker ps -a                  # All

Stop/Start

docker stop container_name
docker start container_name
docker restart container_name

Remove Container

docker rm container_name
docker rm -f container_name   # Force
docker container prune        # All stopped

Execute Command

docker exec -it container_name bash
docker exec container_name ls /app

Dockerfile

5 snippets

Define container images

Basic Dockerfile

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

Multi-stage Build

# Build stage
FROM node:18 AS builder
WORKDIR /app
COPY . .
RUN npm run build

# Production stage
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html

ARG & ENV

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
ENV PORT=3000

ENTRYPOINT vs CMD

# ENTRYPOINT: always runs
ENTRYPOINT ["node"]
# CMD: default args, can override
CMD ["app.js"]

Health Check

HEALTHCHECK --interval=30s --timeout=3s \
  CMD curl -f http://localhost/ || exit 1

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Docker Compose

4 snippets

Multi-container applications

Basic compose.yml

services:
  web:
    build: .
    ports:
      - "8080:80"
    volumes:
      - ./src:/app/src
    environment:
      - NODE_ENV=development

Multiple Services

services:
  app:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db
  db:
    image: postgres:15
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:

Compose Commands

docker compose up             # Start
docker compose up -d          # Detached
docker compose up --build     # Rebuild
docker compose down           # Stop & remove
docker compose logs -f        # Follow logs

Scale Services

docker compose up -d --scale worker=3

Volumes & Networks

6 snippets

Data persistence and networking

Create Volume

docker volume create mydata

List Volumes

docker volume ls

Mount Volume

docker run -v mydata:/app/data nginx
docker run -v ./local:/app/data nginx

Create Network

docker network create mynet

Connect to Network

docker run --network mynet nginx
docker network connect mynet container_name

Inspect

docker volume inspect mydata
docker network inspect mynet

Cleanup

4 snippets

Remove unused resources

Remove All Stopped

docker container prune

Remove Dangling Images

docker image prune

Remove All Unused

docker system prune
docker system prune -a  # Include unused images

View Disk Usage

docker system df

More Cheat Sheets

FAQ

Frequently asked questions

What is a Docker cheat sheet?

A Docker cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Docker. It helps developers quickly look up syntax without searching through documentation.

How do I learn Docker quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Docker concepts?

Key Docker concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Docker code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Docker code using AI.

Code Conversion Tools

Convert Docker to Other Languages

Easily translate your Docker code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate Docker Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week