Skip to content
Latchkey

Docker Cheat Sheet: Commands, Dockerfile & Compose

Every Docker command and Dockerfile instruction you forget, in one reference.

The CLI, Dockerfile, and compose essentials for local dev and CI.

CLI essentials

CommandDoes
docker build -t name .Build an image
docker run --rm -it nameRun a container
docker ps -aList containers
docker imagesList images
docker logs -f idFollow logs
docker exec -it id shShell into a container
docker system prune -af --volumesReclaim disk (CI-safe)

Dockerfile instructions

InstructionPurpose
FROMBase image
RUNExecute at build time
COPY / ADDAdd files
WORKDIRSet working dir
ENVSet env var
EXPOSEDocument port
ENTRYPOINT / CMDDefault process

BuildKit cache (CI)

Terminal
docker buildx build \
  --cache-from type=gha \
  --cache-to type=gha,mode=max \
  -t myimage:latest .

Compose

CommandDoes
docker compose up -dStart services
docker compose buildBuild services
docker compose logs -fFollow logs
docker compose down -vStop + remove volumes

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →