Docker development

From borghei/Claude-Skills · View interactive version

Docker development is an AI agent skill from the GitHub repository borghei/Claude-Skills. Analyse Dockerfiles and Compose files for security, image size, cache and config problems, with CI-ready exit codes. Use when reviewing or optimising a Dockerfile, validating docker-compose, or adding a container lint step.

How to use this skill

Skill file

Docker Development

The agent reviews Dockerfiles and Compose files the way a careful platform engineer would: security first (root user, secrets, privileged containers, floating tags), then image size and build-cache order, then operability (health checks, restart policies, resource limits). The two analyzers catch the mechanical issues so the review can focus on the design.

When to Use

Clarify First

Before running the analysis, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.

Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.

Workflow

  1. Analyse the Dockerfile with dockerfile_analyzer.py and the Compose file with compose_validator.py.
  2. Fix critical findings first: secrets in ENV/environment, root user, privileged mode, host port conflicts. Then floating tags, then layer and cache order, then health checks and limits.
  3. Change the design where the findings point to it: a multi-stage build when build tools ship in the runtime image, a non-root USER, dependency files copied before source.
  4. Verify by rerunning both tools (critical count must be 0), then a real docker build and docker compose config to confirm the files still work. The analyzers read text; only a build proves the image.

Quick Start

python3 scripts/dockerfile_analyzer.py --file examples/Dockerfile.sample                 # latest tag, ENV secret, root (exit 1)
python3 scripts/compose_validator.py --file examples/docker-compose.sample.yml          # port clash, privileged, literal passwords (exit 1)
python3 scripts/compose_validator.py --file examples/docker-compose.sound.yml           # clean (exit 0)
python3 scripts/compose_validator.py --file examples/docker-compose.sample.yml --check-ports   # port check only

In CI, write one report per tool (two JSON documents in one file is not valid JSON) and gate on the exit codes:

python3 scripts/dockerfile_analyzer.py --file Dockerfile --format json > dockerfile-report.json
python3 scripts/compose_validator.py --file docker-compose.yml --format json > compose-report.json

Tools Overview

| Tool | Checks | Key flags | Exit codes |

|------|--------|-----------|------------|

| dockerfile_analyzer.py | Root user, latest/untagged base, secrets in ENV/ARG, oversized base images, runs of consecutive RUN layers, missing --no-install-recommends, cache-breaking COPY . before installs, single-stage builds with many steps, missing HEALTHCHECK, missing .dockerignore next to the Dockerfile | --file, --security-only, --format text|json | 0 no critical, 1 critical finding, 2 file not found |

| compose_validator.py | Structure, circular depends_on, host port conflicts, Docker socket and sensitive mounts, privileged and host network mode, floating image tags, literal passwords/secrets/tokens in environment, restart policy, resource limits | --file, --check-ports (runs only the port check), --format text|json | 0 no critical, 1 critical finding, 2 file not found |

Anti-Patterns

Mistake: Treating a clean analyzer run as a container security review.

Why it happens: Zero findings looks like approval.

Instead: The rules are text checks. Scan the built image for CVEs (Trivy, Grype or the registry's scanner) and review runtime privileges separately.

Mistake: "Fixing" a secret finding by moving the value to a build ARG.

Why it happens: The warning disappears from ENV.

Instead: Build args are stored in image history. Use BuildKit secrets (RUN --mount=type=secret) for build-time secrets and runtime environment or secret stores for the rest.

Mistake: Switching every base image to Alpine for size.

Why it happens: Smaller looks strictly better.

Instead: musl breaks some native wheels and binaries. Prefer -slim or distroless when Alpine causes rebuilds from source, and confirm with a test build.

Files

Scope & Limitations

In Scope:

Out of Scope:

Important Caveats:

Reference Documentation

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.