Active Nerds
Back to Cheat Sheets
Topic Reference

Docker Cheat Sheet

Quick reference guide for Docker commands, Dockerfile directives, Compose syntax, and storage drivers.

Last updated: 2026-07-25

Image Commands

Command / PatternDescription
docker build -t name:tag .

Build an image from a Dockerfile in current directory using BuildKit.

docker pull name:tag

Fetch an image manifest and layer blobs from an OCI registry.

docker push name:tag

Upload local image layers and manifest to a target registry.

docker images

List locally cached images with repository, tag, ID, and size.

docker rmi image_id

Remove specified image layers from host local storage if unused.

docker history image_id

Inspect step instructions and size contribution of each layer blob.

docker inspect image_id

Output full JSON metadata spec for an image manifest.

Container Lifecycle Commands

Command / PatternDescription
docker run -d -p 8080:80 --name app image

Launch container detached in background with host-to-container port mapping.

docker ps -a

List all container process instances (running, stopped, exited).

docker exec -it container_id /bin/sh

Open an interactive pseudo-TTY shell inside a running container.

docker logs -f --tail 100 container_id

Stream container stdout/stderr log stream continuously.

docker stop container_id

Send SIGTERM signal to main process, defaulting to SIGKILL after 10 seconds.

docker rm -f container_id

Forcefully kill running container process and delete its top write layer.

docker stats

Display live stream of container CPU, memory, network I/O usage.

Docker Compose

Command / PatternDescription
docker compose up -d

Build, recreate, and start multi-container environment in detached mode.

docker compose down -v

Stop services and purge internal networks and named volume mounts.

docker compose logs -f service_name

Tail output logs for a specific service defined in compose file.

docker compose ps

List status and ports of containers linked to current compose context.

Dockerfile Directives

Command / PatternDescription
FROM image:tag AS stage

Specify base image layer and assign stage name for multi-stage builds.

RUN command

Execute shell build command, committing output as a new read-only image layer.

COPY --from=stage src dst

Copy files from host build context or earlier stage build artifact.

ENV KEY=VALUE

Set environment variable persistent in both build steps and runtime process.

CMD ["executable", "arg1"]

Define default execution arguments for container launch (overridable by CLI).

ENTRYPOINT ["executable"]

Set fixed binary executable for container runtime process.