Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026
All cheatsheets
Docker · Cheatsheet

Docker Cheatsheet

Build, run, debug, prune. Multi-stage builds, BuildKit, compose, registry auth, and the production-only flags every engineer forgets.

Updated 2026-05-21 8 min

Images

docker build -t app:1.0 .Build with tag
docker build --target prod -t app:prod .Build a specific multi-stage target
DOCKER_BUILDKIT=1 docker build .Force BuildKit (faster, secrets support)
docker build --secret id=npmrc,src=$HOME/.npmrc .Mount build-time secret (BuildKit)
docker images --filter dangling=trueList untagged layers
docker image prune -af --filter 'until=24h'Delete images older than 24h
docker history app:1.0Inspect layers + sizes
docker save app:1.0 | gzip > app.tgzExport image to tarball

Containers

docker run -d --name api -p 8080:8080 app:1.0Detached + named + port-map
docker run --rm -it alpine shThrowaway shell
docker run --read-only --tmpfs /tmp appReadOnly rootfs, writable /tmp
docker run --user 10001:10001 appNon-root UID/GID
docker run --cap-drop=ALL --security-opt no-new-privileges appHardened defaults
docker exec -it api shShell into a running container
docker logs -f --tail 100 apiTail last 100 lines, follow
docker statsLive CPU/mem of all containers

Networking & volumes

docker network create app-netCreate user-defined bridge
docker run --network app-net --name db postgresAttach to network
docker volume create pgdataNamed volume
docker run -v pgdata:/var/lib/postgresql/data postgresMount volume
docker run -v $PWD:/app:ro alpineBind-mount read-only
docker port apiShow port mappings
docker inspect -f '{{.NetworkSettings.IPAddress}}' apiGet container IP

Compose (v2)

docker compose up -dStart in background
docker compose logs -f apiFollow one service
docker compose exec api shShell into a service
docker compose build --no-cache apiRebuild without cache
docker compose down -vStop & remove volumes
docker compose --profile dev upActivate a profile
docker compose configRender the effective merged config

Registry & auth

docker login ghcr.ioLogin to GHCR
aws ecr get-login-password | docker login --username AWS --password-stdin <acct>.dkr.ecr.<region>.amazonaws.comECR login
docker tag app:1.0 ghcr.io/org/app:1.0Re-tag for push
docker push ghcr.io/org/app:1.0Push to registry
docker manifest inspect alpine:latestView image manifest + digests

Dockerfile best practices

FROM alpine:3.20 AS buildPin minor version, name stages
RUN apk add --no-cache curlalpine: skip cache
COPY --chown=10001:10001 . /appSet owner during COPY
USER 10001:10001Never run as root
HEALTHCHECK --interval=30s CMD curl -f http://localhost:8080/health || exit 1Container-level health
ENTRYPOINT ["/app/api"]Exec form — handles signals correctly
# .dockerignore: node_modules, .git, *.logSmaller context = faster builds

Cleanup & troubleshooting

docker system dfDisk usage breakdown
docker system prune -af --volumesNuke everything unused (careful!)
docker inspect <id>Full JSON config + state
docker events --since 10mLive event stream
docker run --rm -it --pid=host --network=host nicolaka/netshootNetwork debug toolkit

Want the full hands-on training behind this?

Cloudadhar batches walk you through every command in a real production setup — with labs, code reviews, and 1:1 doubt sessions.