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
| Command | Does |
|---|---|
| docker build -t name . | Build an image |
| docker run --rm -it name | Run a container |
| docker ps -a | List containers |
| docker images | List images |
| docker logs -f id | Follow logs |
| docker exec -it id sh | Shell into a container |
| docker system prune -af --volumes | Reclaim disk (CI-safe) |
Dockerfile instructions
| Instruction | Purpose |
|---|---|
| FROM | Base image |
| RUN | Execute at build time |
| COPY / ADD | Add files |
| WORKDIR | Set working dir |
| ENV | Set env var |
| EXPOSE | Document port |
| ENTRYPOINT / CMD | Default process |
BuildKit cache (CI)
Terminal
docker buildx build \
--cache-from type=gha \
--cache-to type=gha,mode=max \
-t myimage:latest .Compose
| Command | Does |
|---|---|
| docker compose up -d | Start services |
| docker compose build | Build services |
| docker compose logs -f | Follow logs |
| docker compose down -v | Stop + remove volumes |
Related guides
Docker "no space left on device" - Causes and FixesWhy Docker builds fail with "no space left on device" in CI, and how to reclaim space, prune layers, and stop…
How to Cache Docker Layers in GitHub ActionsSpeed up Docker builds in GitHub Actions with BuildKit registry cache - cache-from/cache-to, gha cache backen…
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…