Skip to content
Back to skills

Docker Development

ASecurity

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.

  • 1,271 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added May 27, 2026
data-aipythongobashdockerkubernetesdevopssecuritydocumentation

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add borghei/Claude-Skills --skill docker-development --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Docker Development?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Docker Development
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/borghei-docker-development/badge)](https://www.skillsdirectory.com/skills/borghei-docker-development)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: docker-development
description: >
  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.
license: MIT + Commons Clause
metadata:
  version: 1.0.0
  author: borghei
  category: engineering
  domain: containers
  updated: 2026-11-08
  tags: [docker, containers, devops, compose, dockerfile]
---
# 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

- Reviewing or optimising a Dockerfile (size, cache hits, security).
- Validating a docker-compose file before it is shared or deployed.
- Adding a container lint step to CI.

## 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.

- **Target file:** which Dockerfile or docker-compose.yml to analyze (sets `--file` and which tool runs).
- **Focus:** full analysis vs security-only, and whether to check port conflicts (sets `--security-only`/`--check-ports`).
- **Output mode:** human-readable vs JSON for CI (sets `--format json` and whether findings gate a pipeline).

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 (exit 0, no critical or warning findings), 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

```bash
python3 scripts/dockerfile_analyzer.py --file assets/Dockerfile.flawed                  # latest tag, ENV secret, root (exit 1)
python3 scripts/dockerfile_analyzer.py --file assets/Dockerfile.sound                   # clean (exit 0)
python3 scripts/compose_validator.py --file assets/docker-compose.flawed.yml            # port clash, privileged, literal passwords (exit 1)
python3 scripts/compose_validator.py --file assets/docker-compose.sound.yml             # clean (exit 0)
python3 scripts/compose_validator.py --file assets/docker-compose.flawed.yml --check-ports   # port check only (exit 1)
python3 scripts/dockerfile_analyzer.py assets/Dockerfile.malformed                      # unusable input (exit 2)
```

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

```bash
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
```

Real output of the sound Compose sample (exit 0):

```
Services found: 2
  - app
  - postgres

Findings: 0 critical, 0 warnings, 0 info
------------------------------------------------------------

No issues found by the structure, dependency, port, volume, security and best-practice checks.
============================================================
PASS
============================================================
```

The flawed sample ends with `FIX <n> issues (critical or warning)` instead of `PASS` and exits 1.

## Exit Codes

| Code | Meaning |
|------|---------|
| 0 | PASS: no critical or warning finding (info findings do not fail) |
| 1 | FIX n: at least one critical or warning finding |
| 2 | Unusable input: missing file, a directory, non-UTF-8 bytes, no `FROM` in a Dockerfile, no top-level `services:` in a Compose file. One-line message, no traceback |

```
$ python3 scripts/dockerfile_analyzer.py assets/Dockerfile.malformed
Error: assets/Dockerfile.malformed has no FROM instruction; it is not a Dockerfile.     (exit 2)
```

## 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 PASS, 1 critical or warning finding, 2 unusable input |
| `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 PASS, 1 critical or warning finding, 2 unusable input |

## 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

- `scripts/dockerfile_analyzer.py`, `scripts/compose_validator.py` — the analyzers.
- `assets/Dockerfile.flawed`, `assets/docker-compose.flawed.yml` (deliberately flawed, exit 1); `assets/Dockerfile.sound`, `assets/docker-compose.sound.yml` (pass, exit 0); `assets/Dockerfile.malformed`, `assets/docker-compose.malformed.yml` (exit 2).
- `assets/contract.json` — commands and expected exit codes used by `scripts/skill_contract_check.py`.

## Scope & Limitations

**In Scope:**
- Dockerfile analysis with `dockerfile_analyzer.py`: layer count, multi-stage use, running as root, `latest` tags, secrets in the file, base image choice and cache-breaking instruction order, with `--security-only` for a narrower report
- Compose file checks with `compose_validator.py`: file structure, circular `depends_on` chains, duplicate host port bindings, volume mounts, security settings and best practices such as restart policies and resource limits
- Text or JSON output for review and CI steps
- Dockerfile and Compose patterns from the Docker best practices reference

**Out of Scope:**
- Building images, running containers or measuring real image size
- Scanning image layers or packages for known CVEs (dependency-level scanning is in `engineering/dependency-auditor/`)
- Kubernetes manifests and Helm charts (see `engineering/kubernetes-operator/` and `engineering/helm-chart-builder/`)
- CI pipeline design around image builds (see `engineering/devops-workflow-engineer/`)

**Important Caveats:**
- Both tools read files as text. The Compose validator uses a small built-in YAML parser, so anchors, merge keys, `extends`, `include` and variable substitution may not be read correctly.
- `compose_validator.py` checks one file per run. Port conflicts or overrides spread across several Compose files are not detected.
- Base image advice is general. Whether `alpine`, `slim` or distroless suits an image depends on its libraries and needs a test build.
- A clean report means the rules found nothing. It is not a container security assessment.

## Reference Documentation

- [references/docker-best-practices.md](references/docker-best-practices.md) — Dockerfile and Compose patterns (multi-stage builds, layer order, non-root users, health checks, secrets) with examples. Read when rewriting a Dockerfile or Compose file.

Files in this skill

  • SKILL.md5.4 KB
  • examples/Dockerfile.sample1.9 KB
  • examples/docker-compose.sample.yml3 KB
  • references/docker-best-practices.md2.7 KB
  • scripts/compose_validator.py14.8 KB
  • scripts/dockerfile_analyzer.py15.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in data-ai →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.