DOCK.REF

DOCKER
YARD.

A working reference for how images get built, how containers run, and every command you'll reach for in between. Laid out like cargo on a dock — stacked, labeled, ready to move.

DOCKERFILE → IMAGE → CONTAINER 40+ COMMANDS
// image layers, bottom to top
CMD ["node","server.js"]L5
COPY . .L4
RUN npm installL3
COPY package.json .L2
FROM node:20-alpineL1
Structure

How an image is built

Every Dockerfile instruction adds one read-only layer on top of the last. Docker caches each layer, so ordering them from least-changing (dependencies) to most-changing (your source code) keeps rebuilds fast.

FROMSets the base image everything else builds on.
WORKDIRSets the working directory for the instructions that follow.
COPY / ADDCopies files from the build context into the image. ADD also handles remote URLs and archive extraction.
RUNExecutes a command at build time and commits the result as a new layer.
ENV / ARGENV sets runtime environment variables. ARG sets build-time-only variables.
EXPOSEDocuments which port the container listens on. Doesn't publish it.
VOLUMEMarks a path as a mount point for persistent or shared data.
USERSets the user the container runs as, instead of root.
CMDDefault command for the container. Overridden by args passed to `docker run`.
ENTRYPOINTFixed executable the container always runs. CMD supplies default arguments to it.
HEALTHCHECKDefines a command Docker runs periodically to judge if the container is healthy.
// container = image + writable layer
Writable container layerRW
CMD ["node","server.js"]L5
COPY . .L4
RUN npm installL3
FROM node:20-alpineL1–2
Flow

Where each command sits

The same image moves through three states: built once, run many times, and shared through a registry. Compose sits alongside this for multi-container setups.

01

Dockerfile

Source of truth for the image.

build
02

Image

Immutable, versioned, taggable.

docker build -t app:1.0 .
run
03

Container

A running instance of the image.

docker run -d -p 3000:3000 app:1.0
push
04

Registry

Where images are stored and pulled from.

docker push app:1.0
Compose File

Running more than one container

docker-compose.yml describes a whole stack — every service, how they connect, and what they depend on — so `docker compose up` can start it all at once.

docker-compose.yml
services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
    depends_on:
      - db
    volumes:
      - ./src:/app/src

  db:
    image: postgres:16
    environment:
      - POSTGRES_PASSWORD=secret
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  db-data:
servicesTop-level list of containers that make up the app. Each key becomes a container name.
buildBuilds an image from a local Dockerfile instead of pulling one.
imageUses an existing image from a registry instead of building.
portsMaps host_port:container_port so a service is reachable from outside.
environmentSets environment variables inside the container.
volumesMounts a host path or named volume into the container for persistent data.
depends_onControls startup order. Doesn't wait for the other service to be ready, only started.
networksAttaches the service to a custom network so services can reach each other by name.
CLI Reference

Commands you'll actually run

Search by command or keyword, or filter by category. Click any command to copy it.

No commands match that search.