Docker Cheatsheet

Images

Use this Docker reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Building Images

docker build -t myapp:1.0 .               # build from Dockerfile in current dir
docker build -t myapp:1.0 -f path/Dockerfile ./ctx   # custom Dockerfile + context
docker build --no-cache -t myapp:latest . # force full rebuild
docker build --target builder -t myapp:dev .  # stop at a named stage
docker build \
  --build-arg NODE_ENV=production \
  --platform linux/amd64 \
  -t myapp:1.0 .

Listing and Inspecting

docker image ls                      # list local images
docker image ls -a                   # include intermediate layers
docker image ls --filter dangling=true   # untagged (<none>) images only
docker image inspect myapp:1.0       # full JSON metadata
docker image inspect -f '{{.Id}}' myapp:1.0   # extract one field
docker image history myapp:1.0       # layer-by-layer size breakdown

Tagging

docker tag myapp:1.0 myapp:latest
docker tag myapp:1.0 registry.example.com/myapp:1.0

Removing Images

CommandWhat it does
docker image rm myapp:1.0Remove one image (alias: docker rmi)
docker image rm $(docker image ls -q)Remove all local images
docker image pruneRemove dangling (untagged) images
docker image prune -aRemove all images not used by a container

Exporting and Importing

# Save to a tar archive (preserves layers and tags)
docker image save myapp:1.0 | gzip > myapp.tar.gz

# Load from tar archive
docker image load < myapp.tar.gz

# Export a container's filesystem (no metadata/layers)
docker export mycontainer | gzip > mycontainer.tar.gz
docker import mycontainer.tar.gz myapp:imported

Searching and Pulling

docker search nginx                           # search Docker Hub
docker search nginx --filter stars=100        # at least 100 stars
docker pull nginx                             # latest tag
docker pull nginx:1.27-alpine                 # specific tag
docker pull --platform linux/arm64 nginx      # force arch

Multi-platform Builds (buildx)

docker buildx create --use --name mybuilder
docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t registry.example.com/myapp:1.0 \
  --push .

docker buildx ls                # list builders
docker buildx inspect --bootstrap

Useful Filters

# Images created before/since another
docker image ls --filter "before=myapp:1.0"
docker image ls --filter "since=myapp:0.9"

# Format output
docker image ls --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
docker image ls --format "{{.ID}}" # IDs only