agentleFS
arjunprabhulalarjunprabhulal/agent-skills/skills/devops/containerization/SKILL.md

containerization

Skill4 starsChanged 4 months agoMITView on GitHub

Packages an application into a container image that is small, reproducible, and safe to run — Dockerfiles, layer caching, multi-stage builds, and runtime configuration. Use this whenever the user is writing a Dockerfile, mentions Docker, container images, image size or build times, or is preparing an application to run in Kubernetes or a container platform. For linting an existing Dockerfile, use code-linting.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use .dockerignore — without it, the build context includes .git, node_modules, and local artifacts, which is slow and can leak secrets into …

    line 30
  2. Distinctive:

    Use a numeric UID as well as a name, some platforms require it to enforce non-root

    line 82
  3. Very specific:

    Do not chown -R the whole application directory.

    line 83
  4. Very specific:

    Never: put secrets in ARG, ENV, or a COPY'd file

    line 94
  5. Distinctive:

    Use BuildKit secret mounts for build-time credentials

    line 95
  6. Distinctive:

    Log to stdout and stderr: Not to files inside the container

    line 105

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Containerization

A container image is a build artifact that should be identical everywhere it runs. Most Dockerfile problems come from treating it as a virtual machine — installing a shell's worth of tooling, running as root, and rebuilding the world on every code change.

Three properties to aim for: small, reproducible, and least-privileged.

1. Order layers by how often they change

Docker caches per layer and invalidates everything after the first change. Put the stable things first:

COPY package.json package-lock.json ./
RUN npm ci                      # cached until dependencies change
COPY . .                        # invalidated on every code change
RUN npm run build

Copying source before installing dependencies means a one-line change re-downloads everything. This single ordering change is usually the largest build-time win available.

Use .dockerignore — without it, the build context includes .git, node_modules, and local artifacts, which is slow and can leak secrets into the image.

Done when: a code-only change does not reinstall dependencies.

2. Use multi-stage builds

Build tooling has no business in a runtime image. Compilers, dev dependencies, and test fixtures add size and attack surface.

FROM node:22-slim AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=build /app/dist ./dist
USER node
CMD ["node", "dist/server.js"]

For compiled languages the runtime stage can often be distroless or scratch — no shell, no package manager, almost nothing to exploit.

Done when: the runtime image contains only what running requires.

3. Pin the base image

  • A specific version tag, never latest. latest makes the build non-reproducible and means the image you tested is not the one you deploy
  • By digest for production — a tag can be repointed
  • Prefer slim or distroless variants, which are smaller and carry far fewer CVEs
  • Rebuild on a schedule to pick up base image patches. A pinned image is reproducible and gets stale; both are true and the answer is scheduled rebuilds, not floating tags

Done when: the base is pinned and there is a plan for patching it.

4. Do not run as root

The default is root, and it is the most common real finding in a container review.

RUN useradd --system --uid 10001 app
USER app
  • Use a numeric UID as well as a name, some platforms require it to enforce non-root
  • Do not chown -R the whole application directory; copy with the right ownership instead
  • The container should not need write access to its own code
  • Drop capabilities and use a read-only root filesystem where the app allows it

Done when: the process runs as a non-root user with no write access it does not need.

5. Keep secrets out of the image

Layers are permanent. A secret added in one layer and deleted in the next is still in the image and readable with docker history.

  • Never put secrets in ARG, ENV, or a COPY'd file
  • Use BuildKit secret mounts for build-time credentials
  • Inject runtime configuration as environment variables or mounted files, not baked in
  • Scan images for embedded credentials before publishing

Done when: docker history reveals nothing sensitive.

6. Configure for the runtime

  • Handle signals. The process must be PID 1 or have an init that forwards SIGTERM, or the platform kills it hard on every deploy and in-flight requests are dropped
  • Log to stdout and stderr. Not to files inside the container
  • Health endpoints: separate liveness from readiness. Readiness must actually check dependencies; liveness must not, or a slow database restarts your app
  • Set resource limits and make sure the runtime respects them. JVMs and Node need explicit configuration to see container memory limits rather than the host's
  • One process per container, and let the platform handle restarts

Done when: the container starts, reports ready accurately, and shuts down cleanly on SIGTERM.

Report

State the final image size, the base image and how it is pinned, the user it runs as, and what the build stages separate. Note anything you could not remove from the runtime image and why — that is the remaining attack surface.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.