Slim down a container image
Rewrites a Dockerfile for a smaller, faster, safer image with multi-stage builds, cache-friendly layers, pinned bases and a non-root user. Use when images are large, slow or flagged by scanners.
Image size, build time and attack surface usually come from the same mistakes: compilers and dev dependencies shipped to production, source copied before dependencies so every code change reinstalls everything, floating base tags, package-manager caches left in layers, secrets passed as build args, and a root user. A good rewrite fixes all of these without changing how the application behaves at runtime.
Rewrite this DockerfileOnly if [RUNTIME] is given: for :
- Work out the runtime, the package manager and the build output from the file. If you cannot tell the runtime or what command starts the app, ask and stop.
- Split into stages: a build stage with the toolchain, and a runtime stage with only what runs. Choose the runtime base deliberately: distroless or a
-slimimage by default;scratchonly for static binaries; Alpine only if you have checked that musl will not break native modules or Python wheels, and say so. - Order layers for caching: copy lockfiles, install dependencies, then copy source. Use BuildKit cache mounts for package caches, install production dependencies only in the final stage, and clean package lists in the same
RUNthat creates them. - Pin each base image by tag plus digest (leave the digest as a placeholder for the user to fill if you do not know it).
- Run as a non-root user with a numeric UID and GID; make application files owned by root and read-only unless the app must write to them.
- Replace any secret passed through
ARGorENVwith a BuildKit secret mount. - Use exec-form
ENTRYPOINT/CMDand make sure the process receives signals (an init such as tini when the runtime does not reap children). - Write a
.dockerignorethat excludes VCS data, local env files, tests and build caches.
- Keep runtime behaviour the same: exposed port, entrypoint semantics, working directory, environment variables and file paths the app reads. List anything you had to change under "Behaviour to check".
- Size and time savings are estimates unless you were given measurements. Label them as estimates.
- Do not add tools the original image did not need (curl, shells) "for debugging".
- Do only what was asked. If you notice something else worth changing, mention it in one line at the end instead of changing it.
- Keep the change as small as it can be while still being correct.
Dockerfile
The full rewritten file in one fenced block, with short comments only where a choice is non-obvious.
.dockerignore
One fenced block.
Changes
A table: change, why, effect on size, build time or security.
Behaviour to check
Bullets, or "None".
Verify
Commands to compare image size and layers before and after, run the container as a non-root user, and scan it.
1 required value still a placeholder; the assistant will ask for it.
details
- kind
- Prompt: a task you run by name to get one finished thing back
- domain
- Software engineering
- category
- DevOps
- level
- Intermediate
- made for
- DevOps / platform engineer, Backend engineer, Software engineer
- risk
- read-only
- version
- v1.0.0 · incubating
- reviewed
- 2026-10-02
- works in
- Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai
use in
npx @hermes-hq/hodios install slim-container-image --target claude-codenpx skills add hermes-hq/hodios-dist --skill slim-container-image -a claude-codeclaude plugin marketplace add hermes-hq/hodios-distclaude plugin install hodios-software-engineering@hodiosThe plugin brings every entry in this domain at once.
pairs well with
All of DevOpsWrite Kubernetes manifests
Writes production-ready Kubernetes manifests for a service with probes, resource requests, a disruption budget and a restricted security context. Use when deploying a service to a cluster.
write-kubernetes-manifestsDesign a deployment strategy
Chooses and specifies a deployment strategy (rolling, blue-green, canary or feature-flagged) with health gates, automated rollback triggers and database-change ordering. Use when deploys feel risky.
design-deployment-strategyReview a Dockerfile
Reviews a Dockerfile for security, image size, build cache use and runtime correctness, and returns ranked findings with a corrected file. Use before shipping a new or changed container image.
review-dockerfileReview an infrastructure plan before apply
Reviews a Terraform, OpenTofu or other IaC plan for destructive changes, security exposure, cost surprises and changes outside the stated intent. Use before running apply, especially in production.
review-iac-planWrite a Docker Compose dev environment
Writes a Docker Compose local development setup that mirrors production dependencies, with health checks, named volumes, seed data, env files and a one-command start. Use when onboarding developers.
write-docker-composeWrite a GitHub Actions workflow
Writes a secure, cached and least-privilege GitHub Actions workflow that fits the repository's real build and test commands. Use when adding CI, a release job or a scheduled task.
write-github-actions-workflow