hermes

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.

context

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.

task

Rewrite this DockerfileOnly if [RUNTIME] is given: for :

  1. 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.
  2. 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 -slim image by default; scratch only for static binaries; Alpine only if you have checked that musl will not break native modules or Python wheels, and say so.
  3. 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 RUN that creates them.
  4. 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).
  5. 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.
  6. Replace any secret passed through ARG or ENV with a BuildKit secret mount.
  7. Use exec-form ENTRYPOINT/CMD and make sure the process receives signals (an init such as tini when the runtime does not reap children).
  8. Write a .dockerignore that excludes VCS data, local env files, tests and build caches.
constraints
  • 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.
output format

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

Edit on GitHubReport a problem

use in

Hodios CLI
npx @hermes-hq/hodios install slim-container-image --target claude-code
Agent Skills
npx skills add hermes-hq/hodios-dist --skill slim-container-image -a claude-code
Add the Hodios marketplace (once)
claude plugin marketplace add hermes-hq/hodios-dist
Install the software-engineering plugin
claude plugin install hodios-software-engineering@hodios

The plugin brings every entry in this domain at once.

pairs well with

All of DevOps
PromptDevOps

Write 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-manifests
PromptDevOps

Design 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-strategy
PromptDevOps

Review 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-dockerfile
PromptDevOps

Review 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-plan
PromptDevOps

Write 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-compose
PromptDevOps

Write 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