Dockerfile レビュー(よくある問題と直し方)
Dockerfile review with fixes
Dockerfile の latest タグ、root 実行、apt のキャッシュ残し、依存インストール前の COPY . .、ENV/ARG の秘密情報、HEALTHCHECK なしなどを行番号つきで指摘し、理由と直し方を説明します。
できること
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や鍵ファイルの COPYHEALTHCHECKなし、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.
FROMwithout a tag or with:latest(digest pins and ARG defaults are taken into account)- Final stage running as root (no
USER, or lastUSERis root) apt-getwithout cleanup,updateandinstallin separate RUNs, missing-yor--no-install-recommends,apk addwithout--no-cache, pip cache left in the layerCOPY . .before installing dependencies, which defeats layer caching- Secret-looking names in
ENV/ARG, inline credentials in RUN, COPY of.envor key files - Missing
HEALTHCHECK, duplicate or shell-formCMD/ENTRYPOINT,ADDfrom URLs, piping curl into sh,sudo,chmod 777,EXPOSE 22, relativeWORKDIR, missing.dockerignoreand more - Handles multi-stage builds, line continuations,
# escape=andRUN <<EOFheredocs
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.
インストール方法
- ダウンロードしたZIPを展開します(中に
dockerfile-review/フォルダとSKILL.mdがあります)。 - フォルダごと、使うエージェントのスキル置き場にコピーします。
- Claude:
~/.claude/skills/(プロジェクト単位なら.claude/skills/) - Hermes Agent:
~/.hermes/skills/ - Codex:
~/.agents/skills//Cursor:~/.cursor/skills/ - Claude アプリ(claude.ai):「カスタマイズ → スキル」からZIPをアップロード
- Claude:
- エージェントを再起動し、スキル一覧に表示されることを確認します。
出品者
出品スキル 44 件