kmaruthi2002/universal-llm-skills/containerization

Claude Code and agent skill by kmaruthi2002/universal-llm-skills

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

Write, review, and optimise container images and local container setups: Dockerfiles/Containerfiles, base image choice, layer ordering and build caching, multi-stage builds, image size, running as non-root, signals and PID 1, health checks, configuration via environment, Compose for local development, and image scanning and signing. Use when someone asks to dockerize an app, write or fix a Dockerfile, shrink an image, speed up docker builds, set up docker-compose for local dev, harden a container, or fix a container that works locally but not in production. Not for orchestrating containers in a cluster (see kubernetes).

Install

npx vskill@latest install kmaruthi2002/universal-llm-skills/containerization

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as kmaruthi2002/universal-llm-skills/containerization.

Containerization

A container image is a frozen, portable filesystem plus a start command. A good image is small, rebuilds quickly when code changes, starts and stops cleanly, runs with the least privilege it needs, contains no secrets, and produces the same behaviour on a laptop, in CI, and in production. Most container problems come from treating a Dockerfile as a shell script that "gets the app running" rather than as a build artifact with caching, security, and runtime semantics.

Examples use Docker/BuildKit syntax because it is the most common; the same ideas apply to Podman, Buildah, nerdctl, kaniko, ko, Jib, Cloud Native Buildpacks, and others.

Scope

Covers: Dockerfile authoring, base images, layer caching, multi-stage builds, image size, users and permissions, signals, health checks, runtime configuration, local development with Compose, image scanning, signing, and registries.

Hands off to:

  • Running containers on a cluster (deployments, probes as k8s objects, scaling) → kubernetes.
  • Building and publishing images in the pipeline → ci-cd-pipelines.
  • Choosing a container platform vs. serverless vs. VMs → cloud-architecture.
  • Dependency pinning and updates in general → dependency-management.

Core principles

1. One process concern per container. A container should run one main process (which may have worker threads or child processes it manages). Running a web server, a cron daemon, and a database in one container defeats independent scaling, restarts, health checking, and logging. Use separate containers and compose them.

2. Images are immutable; configuration is injected. Build one image and configure it per environment through environment variables, mounted config files, or a secret store at runtime. An image baked with ENV=production and a database URL cannot be promoted through environments (see ci-cd-pipelines, "build once").

3. Layer order is cache order. Each instruction creates a layer; a change invalidates that layer and every layer after it. Put what changes least (OS packages, dependency manifests and installs) first and what changes most (application source) last. This alone often turns a 5-minute rebuild into 10 seconds.

4. Ship only what runs. Compilers, build tools, test fixtures, package caches, and source for compiled languages have no place in the runtime image. They add size, startup time, and attack surface. Multi-stage builds make this easy.

5. Least privilege by default. Run as a non-root user, with a read-only root filesystem where possible, no extra Linux capabilities, and no secrets in the image. Container isolation is not a strong security boundary on its own; root in a container is much closer to root on the host than people assume.

6. Be a good PID 1. The container's main process receives signals (SIGTERM on stop) and must shut down gracefully; it also inherits zombie-reaping duty. Exec-form entrypoints and a proper init (or a runtime that handles it) prevent slow, unclean shutdowns.

7. Reproducible builds. Pin base images (tag plus digest for production), lock dependencies, and avoid apt-get upgrade-style unpinned changes. Otherwise two builds of the same commit differ and debugging becomes guesswork.

Discovering context first

  1. Look for existing Dockerfile, Containerfile, *.dockerfile, .dockerignore, compose.yaml / docker-compose.yml, devcontainer.json, skaffold.yaml, Tiltfile, buildpack configs (project.toml), or language-native image builders (Jib, ko).
  2. Identify language, runtime version, and package manager from the project files (lockfiles, version files like .nvmrc, .python-version, go.mod, rust-toolchain.toml). Match the image's runtime version to what the project pins.
  3. Find how the app is started in production today (Procfile, systemd unit, start scripts) and which ports, env vars, and files it needs.
  4. Check the target platform: CPU architecture (amd64 vs. arm64 — Apple Silicon laptops and ARM cloud instances make multi-arch builds common), orchestrator, any platform-imposed constraints (e.g. read-only filesystems, required non-root, specific port binding).
  5. Check organisational rules: approved base images, internal registries/mirrors, mandatory scanning, labels.
  6. Follow existing conventions (naming, label schema, directory layout, how config is passed) unless they are actively harmful; if so, say why.

Process

  1. Get it running correctly first, in the simplest working form, verifying the app starts and serves.
  2. Add a `.dockerignore` before optimising: exclude .git, dependency directories (node_modules, .venv, target/), build output, local env files, secrets, logs, editor files. This shrinks the build context, speeds builds, and prevents leaking .env files into images.
  3. Restructure for caching: copy dependency manifests and lockfiles, install dependencies, then copy source.
  4. Split into build and runtime stages.
  5. Harden: non-root user, minimal base, no secrets, exec-form entrypoint, health check if appropriate.
  6. Measure: image size (docker image ls, dive or similar for per-layer analysis), cold and warm build times, start time.
  7. Scan for vulnerabilities and fix what matters.
  8. Verify runtime behaviour: graceful stop, config via env, runs as non-root, works with a read-only filesystem if targeted.

Base image choice

Base familySize (approx)ProsConsChoose when
Full distro (e.g. debian, ubuntu)75–130 MB+Familiar, all tools, glibcLarger, more CVEs to triageNeed many system packages; debugging convenience matters
Slim distro (e.g. debian:*-slim, language -slim tags)25–80 MBglibc compatibility, smallerFewer toolsGood default for interpreted languages
Alpine~5–10 MBTiny, simple package managermusl libc: some binary wheels/native modules break or are slow to build; DNS and locale quirksSmall static-ish apps; team knows musl caveats
Distroless / minimal (e.g. Google distroless, Chainguard/Wolfi-based, UBI micro)2–30 MBNo shell or package manager, very few CVEsHarder to debug in placeProduction runtime stage for compiled or bundled apps
scratch0Nothing but your binaryNeed static binary, CA certs, tzdata, user handled manuallyStatic Go/Rust binaries
Language official images (e.g. python, node, eclipse-temurin)VariesCorrect runtime preinstalledPick the slim variantMost apps; use as build stage at least

Heuristics:

  • For Python with native dependencies, prefer slim glibc images over Alpine; manylinux wheels install instantly on glibc, while on musl they may compile from source for minutes or fail.
  • For Go/Rust, build in a full toolchain image and copy the binary into distroless or scratch. Remember CA certificates (for TLS) and timezone data if the app needs them.
  • For JVM apps, use a JRE (not JDK) runtime image, or a jlink'd minimal runtime; set container-aware memory flags (modern JVMs respect cgroup limits, but heap percentage settings like -XX:MaxRAMPercentage deserve explicit thought).
  • For Node, install production dependencies only in the runtime stage (npm ci --omit=dev or equivalent) or copy a pruned node_modules from the build stage.
  • Pin by digest for production reproducibility (image:tag@sha256:...) and let an automated dependency tool propose updates; floating tags silently change.

Layering and caching

Illustrative ordering (Node example; adapt to the project's language):

dockerfile
# syntax=docker/dockerfile:1
FROM node:20-slim AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm ci
COPY . .
RUN npm run build
FROM node:20-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev
COPY --from=build /app/dist ./dist
USER node
EXPOSE 8080
CMD ["node", "dist/server.js"]

What it demonstrates: manifests before source, a BuildKit cache mount for the package manager download cache (persists across builds without bloating layers), a separate runtime stage with only production dependencies, a non-root user that the base image already provides, and exec-form CMD.

Other caching rules:

  • Combine related package-manager commands in one RUN and clean caches in the same layer (apt-get update && apt-get install -y --no-install-recommends ... && rm -rf /var/lib/apt/lists/*). Deleting files in a later layer does not shrink the image; the earlier layer still contains them.
  • Never run apt-get update in its own layer: the cached update goes stale while later installs change, producing "package not found" errors.
  • COPY . . early is the most common cache killer. So is a build step that stamps the current time or git SHA into a file early in the build; pass such metadata late or as labels.
  • ARG values used early invalidate everything after them when they change; place volatile args late.
  • In CI, ephemeral runners start with no local cache. Use registry or CI-backed cache export/import (--cache-to/--cache-from with BuildKit, or the CI system's native Docker cache).

Multi-stage builds

  • Use named stages (AS build, AS test, AS runtime) and COPY --from=<stage> to move only artifacts forward.
  • A test stage can run unit tests during the build (docker build --target test), which ensures tests ran against the same dependencies the image uses. Keep it out of the default target so production builds do not require test dependencies.
  • A dev stage with hot-reload tooling can share the dependency layers with production, keeping local and production images aligned.
  • BuildKit builds independent stages in parallel and skips stages not needed for the requested target.

Size

Size matters for pull time (cold starts, autoscaling speed, node disk pressure), registry cost, and attack surface. Rough targets: compiled apps on distroless/scratch 10–50 MB; interpreted apps on slim bases 100–300 MB; anything over 1 GB deserves investigation unless it legitimately carries large models or toolchains.

Where size usually hides:

  • Build tools and compilers left in the runtime image (fix: multi-stage).
  • Package manager caches and apt lists (fix: cache mounts or same-layer cleanup).
  • Dev dependencies (fix: production-only install).
  • Large files copied by an over-broad COPY or missing .dockerignore (fix: ignore file, targeted copies).
  • Files deleted in a later layer (fix: never create them in the image layer, or squash via multi-stage).
  • chown -R in a separate layer after copying, which duplicates every file (fix: COPY --chown=user:group).
  • ML models or data baked in. Sometimes correct (immutable, versioned with code); often better pulled at startup or mounted from a volume/object store. Decide based on how often the model changes vs. the code and how cold-start sensitive the workload is.

Use a layer inspection tool (e.g. dive, docker history) to find the big layers rather than guessing.

Users, permissions, and hardening

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/kmaruthi2002/universal-llm-skills/containerization/badge)](https://verified-skill.com/skills/kmaruthi2002/universal-llm-skills/containerization)

Something wrong with this skill or its page? Tell us.