container-image-optimization
Skill1 starsChanged 32 days agoMITView on GitHub
Make container images smaller, faster to build and pull, and with fewer vulnerabilities — multi-stage builds, minimal base images, layer ordering and cache mounts, .dockerignore, non-root runtime and reproducible tags. Use when images are large or slow to build, when scanners report many base-image CVEs, or when preparing images for production.
- Installs packages
In this repository105 other files it gives its agents.
- AGENTS.mdAGENTS.md
- instructions/AGENTS.mdAGENTS.md
- accessibility-reviewSkill
- agent-evaluationSkill
- agent-guardrailsSkill
- agenthub-routerSkill
- ai-red-teamingSkill
- ansible-reviewSkill
- api-designSkill
- api-integrationSkill
- architecture-decisionSkill
- backup-restoreSkill
- caching-strategySkill
- chaos-engineeringSkill
- ci-cd-pipeline-designSkill
- cloud-cost-optimizationSkill
- cloud-iam-least-privilegeSkill
- code-reviewSkill
- cyber-resilience-actSkill
- database-migrationsSkill
- data-pipeline-reviewSkill
- data-privacySkill
- data-quality-checksSkill
- debugging-root-causeSkill
- dependency-auditSkill
- dependency-upgradeSkill
- disaster-recovery-drillSkill
- docker-hardeningSkill
- documentationSkill
- dora-readinessSkill
- dpiaSkill
- email-deliverabilitySkill
- embedding-model-selectionSkill
- error-handling-reviewSkill
- eu-ai-act-readinessSkill
- eu-data-sovereigntySkill
- european-accessibility-actSkill
- event-driven-architectureSkill
- feature-flagsSkill
- frontend-reviewSkill
- gdpr-dsar-handlingSkill
- github-actionsSkill
- gitlab-ciSkill
- git-workflowSkill
- go-developmentSkill
- graphql-api-reviewSkill
- helm-chart-reviewSkill
- i18n-localizationSkill
- incident-responseSkill
- java-spring-reviewSkill
- kubernetes-reviewSkill
- linux-server-hardeningSkill
- llm-cost-analysisSkill
- llm-gateway-routingSkill
- llm-observabilitySkill
- llm-output-evaluationSkill
- llm-structured-extractionSkill
- load-testingSkill
- local-llm-servingSkill
- log-analysisSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 43
Do not push optimized images to production tags before tests pass.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Container Image Optimization
Goal
A small, reproducible runtime image that contains only what the application needs at run time, builds quickly from cache and runs as non-root.
Inputs
- Current Dockerfile, image size and layer breakdown (
docker history,dive), build time, vulnerability scan results, runtime requirements (shell, CA certificates, time zone data).
Procedure
- Measure: size per layer, total build time, cold and warm cache; scan with Trivy or Grype and note base-image versus application findings.
- Multi-stage build: compile and install build dependencies in a builder stage; copy only artifacts into the runtime stage.
- Minimal base: distroless,
-slimor Alpine (check musl compatibility for your language), orscratchfor static binaries; pin by digest and update deliberately. - Layer ordering: copy dependency manifests and install dependencies before copying source code; use BuildKit cache mounts (
RUN --mount=type=cache,...) for package caches. - Context hygiene:
.dockerignoreexcludes.git, local environments, test data, secrets and build outputs. - Remove build tools from runtime: compilers, package managers (pip, npm) and shells where the application does not need them; clean package caches in the same layer that creates them.
- Runtime hardening:
USERnon-root with a fixed UID; read-only root file system compatibility; health check; correct signal handling (exec formCMD, or a tiny init). - Reproducibility: no
latesttags;SOURCE_DATE_EPOCHand pinned versions where supported; label images with source revision (org.opencontainers.image.revision).
Example fixture
FROM python:3.13
COPY . /app
RUN pip install -r /app/requirements.txt
CMD python /app/main.pyExpected findings: full base image (~1 GB), source copied before dependencies (cache busts on every change), .git and tests in image, root user, shell-form CMD.
Acceptance checks
- Size, build time and vulnerability counts recorded before and after, with the same scanner version.
- The optimized image passes the application's smoke tests and runs as non-root.
- Negative case: a code-only change rebuilds without reinstalling dependencies (cache hit shown in build log).
Output
Revised Dockerfile, .dockerignore, measurements and scan comparison.
Safety
Do not push optimized images to production tags before tests pass. Never copy secrets into images, even into builder stages — use build secrets.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

