kmaruthi2002/universal-llm-skills/containerization
Claude Code and agent skill by kmaruthi2002/universal-llm-skills
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
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/containerizationSemi-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
- 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). - 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. - Find how the app is started in production today (Procfile, systemd unit, start scripts) and which ports, env vars, and files it needs.
- 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).
- Check organisational rules: approved base images, internal registries/mirrors, mandatory scanning, labels.
- Follow existing conventions (naming, label schema, directory layout, how config is passed) unless they are actively harmful; if so, say why.
Process
- Get it running correctly first, in the simplest working form, verifying the app starts and serves.
- 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.envfiles into images. - Restructure for caching: copy dependency manifests and lockfiles, install dependencies, then copy source.
- Split into build and runtime stages.
- Harden: non-root user, minimal base, no secrets, exec-form entrypoint, health check if appropriate.
- Measure: image size (
docker image ls,diveor similar for per-layer analysis), cold and warm build times, start time. - Scan for vulnerabilities and fix what matters.
- Verify runtime behaviour: graceful stop, config via env, runs as non-root, works with a read-only filesystem if targeted.
Base image choice
| Base family | Size (approx) | Pros | Cons | Choose when | |
|---|---|---|---|---|---|
Full distro (e.g. debian, ubuntu) | 75–130 MB+ | Familiar, all tools, glibc | Larger, more CVEs to triage | Need many system packages; debugging convenience matters | |
Slim distro (e.g. debian:*-slim, language -slim tags) | 25–80 MB | glibc compatibility, smaller | Fewer tools | Good default for interpreted languages | |
| Alpine | ~5–10 MB | Tiny, simple package manager | musl libc: some binary wheels/native modules break or are slow to build; DNS and locale quirks | Small static-ish apps; team knows musl caveats | |
| Distroless / minimal (e.g. Google distroless, Chainguard/Wolfi-based, UBI micro) | 2–30 MB | No shell or package manager, very few CVEs | Harder to debug in place | Production runtime stage for compiled or bundled apps | |
scratch | 0 | Nothing but your binary | Need static binary, CA certs, tzdata, user handled manually | Static Go/Rust binaries | |
Language official images (e.g. python, node, eclipse-temurin) | Varies | Correct runtime preinstalled | Pick the slim variant | Most 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:MaxRAMPercentagedeserve explicit thought). - For Node, install production dependencies only in the runtime stage (
npm ci --omit=devor equivalent) or copy a prunednode_modulesfrom 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):
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
RUNand 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 updatein 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.ARGvalues 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-fromwith BuildKit, or the CI system's native Docker cache).
Multi-stage builds
- Use named stages (
AS build,AS test,AS runtime) andCOPY --from=<stage>to move only artifacts forward. - A
teststage 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
devstage 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
COPYor 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 -Rin 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
- SKILL.md in the repositoryCheckingskills/containerization/SKILL.md
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
[](https://verified-skill.com/skills/kmaruthi2002/universal-llm-skills/containerization)