Dockerfile レビュー(よくある問題と直し方)

Dockerfile review with fixes

Dockerfile の latest タグ、root 実行、apt のキャッシュ残し、依存インストール前の COPY . .、ENV/ARG の秘密情報、HEALTHCHECK なしなどを行番号つきで指摘し、理由と直し方を説明します。

ClaudeHermes AgentCodexCursorMIT(改変・再配布・商用利用可)Python

できること

Dockerfile を静的にチェックし、セキュリティ・イメージサイズ・ビルドの再現性・キャッシュ効率の問題を行番号つきで指摘します。

  • FROM のタグなし・:latest(ダイジェスト固定や ARG の既定値も考慮)
  • 最終ステージが root のまま動く(USER なし、最後の USER が root)
  • apt-get の後片付けなし、update と install が別の RUN、-y なし、--no-install-recommends なし、apk add の --no-cache なし、pip のキャッシュ残し
  • 依存関係のインストール前に COPY . . していてキャッシュが効かない
  • ENV・ARG の秘密情報らしい名前、RUN に直書きされた認証情報、.env や鍵ファイルの COPY
  • HEALTHCHECK なし、CMD/ENTRYPOINT の重複やシェル形式、ADD の URL 取得、curl | sh、sudo、chmod 777、EXPOSE 22、相対パスの WORKDIR、.dockerignore なし など
  • マルチステージ、行継続、# escape=、RUN <<EOF に対応

使い方

python scripts/dockerfile_lint.py Dockerfile --json dockerfile-review.json

エージェントは結果を文脈と照らして確認し(ベースイメージが非 root ユーザーを設定済みか、Kubernetes で動かすかなど)、修正済みの Dockerfile か差分を提案します。

必要な環境

  • Python 3(標準ライブラリのみ)。Docker 本体は不要です。

注意点

  • 静的チェックのみで、イメージの取得やビルドは行いません。ベースイメージの中身は判定できません。
  • ヒューリスティックなので、珍しい書き方では誤検出することがあります。
  • 一度プッシュしたイメージに秘密が入っていた場合は、Dockerfile を直すだけでなく秘密の再発行が必要です。
English description

Flags latest tags, running as root, apt without cleanup, COPY . before dependency installs, secrets in ENV/ARG and missing HEALTHCHECK, with line numbers, reasons and fixes.

What it does

Statically checks a Dockerfile for security, image size, reproducibility and cache problems, with line numbers.

  • FROM without a tag or with :latest (digest pins and ARG defaults are taken into account)
  • Final stage running as root (no USER, or last USER is root)
  • apt-get without cleanup, update and install in separate RUNs, missing -y or --no-install-recommends, apk add without --no-cache, pip cache left in the layer
  • COPY . . before installing dependencies, which defeats layer caching
  • Secret-looking names in ENV/ARG, inline credentials in RUN, COPY of .env or key files
  • Missing HEALTHCHECK, duplicate or shell-form CMD/ENTRYPOINT, ADD from URLs, piping curl into sh, sudo, chmod 777, EXPOSE 22, relative WORKDIR, missing .dockerignore and more
  • Handles multi-stage builds, line continuations, # escape= and RUN <<EOF heredocs

How to use

python scripts/dockerfile_lint.py Dockerfile --json dockerfile-review.json

The agent confirms each finding in context (does the base image already set a non-root user, is it deployed on Kubernetes, and so on) and proposes a corrected Dockerfile or diff.

Requirements

  • Python 3 (standard library only). Docker itself is not required.

Caveats

  • Static checks only: no image pulls or builds, so the base image contents are not inspected.
  • Heuristic rules can misfire on unusual syntax.
  • If an already pushed image contained a secret, fixing the Dockerfile is not enough: rotate the secret.

インストール方法

  1. ダウンロードしたZIPを展開します(中に dockerfile-review/ フォルダと SKILL.md があります)。
  2. フォルダごと、使うエージェントのスキル置き場にコピーします。
    • Claude:~/.claude/skills/(プロジェクト単位なら .claude/skills/)
    • Hermes Agent:~/.hermes/skills/
    • Codex:~/.agents/skills//Cursor:~/.cursor/skills/
    • Claude アプリ(claude.ai):「カスタマイズ → スキル」からZIPをアップロード
  3. エージェントを再起動し、スキル一覧に表示されることを確認します。

Windows・Mac 別、エージェント別のインストール手順

出品者

AI Skill Market 公式

出品スキル 44 件

出品者のプロフィールとスキル一覧