docker commands

46 commands, each with a one-line explanation. Click a command to copy it, or its title for details.

Commands 46 shown

  • docker buildx build --platform linux/amd64,linux/arm64 -t reg/img:tag --push .

    Cross-compile and push directly to registry with BuildKit

  • docker run --rm -it --env-file .env -p 8000:8000 img:tag

    Local run with env vars from file; --rm auto-removes on exit

  • docker history --no-trunc img:tag

    See each layer, its command, and size; identify bloat

    debug

  • docker system prune -af --volumes

    Remove stopped containers, unused images, networks, volumes

  • docker pull src-reg/img:tag && docker tag src-reg/img:tag dst-reg/img:tag && docker push dst-reg/img:tag

    Re-tag and push to another registry

  • docker save img:tag | gzip > img.tar.gz

    Export an image for air-gapped transfer

  • docker build --build-arg VERSION=1.2.3 --build-arg ENV=prod -t img:tag .

    Pass build-time variables into Dockerfile ARG instructions

  • trivy image --exit-code 1 --severity HIGH,CRITICAL img:tag

    Fail pipeline if HIGH or CRITICAL CVEs found

    security

  • docker sbom img:tag

    Generate Software Bill of Materials for an image (Docker Desktop)

    security

  • docker inspect <container> | jq '.[0].NetworkSettings.Networks'

    Drill into network settings of a running container

    debug · network

  • docker compose up -d --build

    Build and start all services in background

    compose

  • docker compose logs -f --tail=100 <service>

    Stream last 100 lines and follow a compose service

    compose · logs

  • docker compose down -v

    Stop and remove containers, networks, and volumes

    compose

  • docker system df -v

    Detailed breakdown of disk usage per image, container, volume

  • docker exec -it -u root <container> bash

    Enter container as root even if default user is non-root

    debug

  • docker cp ./local-file.conf <container>:/etc/app/config.conf

    Inject a file into a running container without rebuild

    debug

  • docker load < img.tar.gz

    Import an image exported with docker save

  • docker exec -it registry bin/registry garbage-collect /etc/docker/registry/config.yml

    Free disk space in a self-hosted Docker Registry

  • docker build --target builder -t img:builder .

    Build only up to a specific stage in a multi-stage Dockerfile

  • docker build --build-arg APP_VERSION=1.2.3 --build-arg ENV=prod -t myapp:1.2.3 .

    Pass build-time variables to Dockerfile ARG instructions

  • docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest --push .

    Build and push multi-arch image using BuildKit

  • docker history --no-trunc <image>

    Show all layers with full commands and sizes

    debug

  • docker export <container> | tar -tvf - | head -30

    Inspect a container's merged filesystem as a tar stream

    debug

  • docker diff <container>

    Files added (A), changed (C), or deleted (D) in a running container

    debug

  • docker commit -m 'debug snapshot' <container> debug-snapshot:$(date +%s)

    Snapshot a running container's filesystem as an image

    debug

  • docker run --memory=512m --cpus=0.5 --oom-kill-disable=false myapp

    Limit container to 512MB RAM and half a CPU core

    performance

  • docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}'

    One-shot CPU and memory snapshot for all containers

    monitoring

  • docker image prune -f

    Remove all <none>:<none> dangling images

  • docker system prune -a --volumes -f

    Remove stopped containers, unused images, networks, volumes

  • docker cp <container>:/app/config.yaml ./local-config.yaml

    Extract a single file from a running or stopped container

    debug

  • docker compose up -d --build --remove-orphans

    Rebuild and start services, remove containers not in compose file

  • docker compose up -d --scale worker=5

    Run 5 replicas of the worker service

  • docker compose logs -f --tail=100 worker

    Stream last 100 lines of a specific compose service

    logs

  • docker network inspect bridge | jq '.[0].Containers | to_entries[] | .value | {Name, IPv4Address}'

    Show IPs of all containers in the bridge network

    network

  • docker network create --driver bridge --subnet 172.30.0.0/24 mynet

    Create a bridge network with a custom subnet

    network

  • docker save myapp:1.0 | gzip > myapp.tar.gz && docker load < myapp.tar.gz

    Export image to archive and reimport on another host

  • HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD curl -sf http://localhost:8080/health || exit 1

    Native Docker healthcheck with curl (add to Dockerfile)

  • docker scout cves --only-fixed myapp:latest

    Show only CVEs that already have a fix available

    security

  • docker run --rm -it --pid=host --network=host --privileged nicolaka/netshoot

    Full-featured network debug container sharing host PID and network

    debug · network

  • docker buildx bake -f docker-bake.hcl --push

    Build/push multiple targets from one HCL file; parallel, DRY group definitions

    buildkit · ci · performance

  • docker buildx imagetools inspect <reg>/<name>:tag --format '{{json .Manifest}}'

    Show platforms in a manifest list without pulling layers; verify arm64+amd64

    buildkit · troubleshooting · cloud

  • docker buildx create --name multi --use --driver docker-container --driver-opt network=host

    Create a BuildKit builder supporting multi-arch and cache export; default driver cannot

    buildkit · ci

  • docker buildx build --secret id=token,src=token.txt -t <name> .

    Feed a secret to BuildKit; only RUN --mount=type=secret,id=token sees it, not history

    buildkit · secrets · security

  • docker context create remote --docker host=ssh://<host> && docker context use remote

    Run docker against a remote daemon over SSH; no exposed TCP socket needed

    network · security

  • docker run --read-only --tmpfs /tmp --security-opt no-new-privileges --cap-drop ALL <name>

    Immutable rootfs, writable /tmp only, block privilege escalation; container hardening

    security · kernel

  • docker events --filter event=oom --filter type=container

    Stream live OOM events to catch memory-limited containers being killed

    monitoring · troubleshooting · performance