Skip to content
Skills Library
DevOps & cloud · Building & coding

docker-image-optimization

/docker-image-optimization

Build small, fast, secure container images with layer caching, multi-stage builds, and a minimal base policy. Use when images are bloated, slow to build, or failing security scans.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Build small, fast, secure container images with layer caching, multi-stage builds, and a minimal base policy. Use when images are bloated, slow to build, or failing security scans.

Original author description

Build small, fast, secure container images with layer caching, multi-stage builds, and a minimal base policy. Use when images are bloated, slow to build, or failing security scans.

How it works

  1. Method
  2. Boundaries
Original SKILL.md headings · 70 lines, 445 words
SKILL.md preview
---
name: docker-image-optimization
description: Build small, fast, secure container images with layer caching, multi-stage builds, and a minimal base policy. Use when images are bloated, slow to build, or failing security scans.
---

# Docker image optimization

A container image has three costs: build time (developer iteration),
size (registry, pull, cold-start), and attack surface (every byte is
something to scan and exploit). Multi-stage builds and disciplined
layering cut all three at once.

## Method

1. **Separate build from runtime with multi-stage.** A build
   stage with the full toolchain compiles/bundles; the final
   stage copies only the artifact into a minimal runtime
   (see artifact-versioning): compilers, dev dependencies,
   and build caches never ship. This single change often
   halves image size and removes most of the CVEs a scanner
   finds.
2. **Order layers by change frequency for cache hits.**
   Dependencies (rarely change) before application code
   (changes every commit): `COPY package.json && install`
   then `COPY . .`, so a code edit does not reinstall every
   dependency. Cache misses on the slow layer are the main
   build-time waste (see deployment-pipelines' speed
   budget); a correctly-ordered Dockerfile rebuilds in
   seconds.
3. **Choose the smallest sufficient base, by policy.**
   Distroless or minimal (alpine, slim, scratch for static
   binaries) over full OS images: less to pull, less to
   patch, less to exploit. Pin base images by digest (not
   `latest`: reproducibility and supply-chain: see
   supply-chain-defense), and standardize the allowed bases
   org-wide so patching is one bump, not fifty
   (see container-security).
4. **Keep each layer clean.** Combine related RUN commands
   and clean up within the same layer (package caches,
   temp files: a separate `rm` layer does not shrink the
   image, it adds one); use `.dockerignore` so build
   context excludes node_modules, .git, and secrets (which
   must never enter an image: see secrets-management). Every
   megabyte multiplies across every pull on every node.
5. **Harden the runtime image.** Run as non-root (see
   kubernetes-workloads' pod security), read-only
   filesystem where possible, no shell/package manager in
   the final image if the app does not need them (smaller
   and drastically reduces post-exploit options), and only
   the ports the app uses. The minimal image is also the
   hardened image: the disciplines converge (see
   least-privilege).
6. **Gate size and scan in CI.** Scan every image for known
   vulnerabilities (see dependency-auditing,
   sast-integration) and track image size with a budget and
   per-PR diff (see bundle-size's twin for containers):
   a base bump that adds 200MB or a new critical CVE fails
   the gate, caught at the commit, not at deploy.

## Boundaries

- Extreme minimization (scratch, distroless) removes
  debugging tools; keep a debug variant or ephemeral
  debug-container workflow so production incidents are
  still investigable (see production-debugging).
- Build-cache optimization interacts with reproducibility
  and multi-arch builds; verify the cache does not mask
  stale dependencies (lockfiles pinned: see
  dependency-management).
- Image optimization reduces attack surface but is not
  container security entire: runtime policy, network
  policy, and secrets handling are separate layers (see
  container-security, cloud-networking).

Versions

The database has no other skills named docker-image-optimization.

Database snapshot: 13.11.2026 · package version a4a082e158ae (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90docker
    Build container images that are reproducible, small, and safe to run — layer order and what actually caches, multi-stage builds, and what belongs in an image versus what must never be baked into one. Use when writing or reviewing a Dockerfile, when an image build is slow,…
  • 95docker-optimization
    Docker image optimization patterns including multi-stage builds, layer caching, security hardening, and size reduction techniques. Use when building Docker images, optimizing container size, improving build performance, or implementing Docker security best practices. Reduces…
  • 100docker-multi-stage-builds-optimization
    Use this skill when optimizing Docker build speed, caching dependencies, and producing minimal production container images.
  • 100docker-multi-stage-builds
    Master production Docker multi-stage builds, container image layer caching, security hardening, non-root user execution, distroless images, and minimal footprint optimizations. Trigger when building Dockerfiles, optimizing image size, or hardening container runtime security.
  • 100docker-development
    Docker and container development agent skill and plugin for Dockerfile optimization, docker-compose orchestration, multi-stage builds, and container security hardening. Use when: user wants to optimize a Dockerfile, create or improve docker-compose configurations, implement…
  • 100image-optimization
    Shrinks container image size and build time — base image choice, layer minimization, dependency pruning, .dockerignore, multi-arch builds, and measuring what actually ends up in the image. Use this whenever the user complains an image is too large, a build or CI pipeline is…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.