dockerfile-optimise — скилл для Claude Code: правила оптимизации
Скилл с 48 правилами из официальной документации Docker: кэш слоёв, multi-stage сборки, безопасность. Пригодится при написании и рефакторинге Dockerfile.
npx skills add pproenca/dot-skills --skill dockerfile-optimise -a claude-codeЧто делает dockerfile-optimise
Скилл подключает к агенту набор правил по Dockerfile, собранных из официальной документации Docker. Всего 48 правил в 8 категориях, отсортированных по влиянию: кэширование слоёв и multi-stage сборки идут как критические, выбор базового образа и работа с секретами — как высокий приоритет, дальше управление зависимостями, паттерны инструкций и проверки качества. У каждого правила есть префикс вроде cache- или sec-, что упрощает поиск.
Внутри — файлы-справки на каждое правило с объяснениями и примерами кода. Агент читает их, когда пишет новый Dockerfile, разбирает существующий на антипаттерны или настраивает сборку в CI. Триггеры срабатывают на задачах про multi-stage, кэш сборки, размер образа и hardening контейнера.
Одна деталь: часть возможностей BuildKit (cache mounts, secret mounts, heredocs, COPY --link) требует директивы syntax в начале Dockerfile. Если её нет, эти правила просто не сработают при сборке. Ставить есть смысл, если вы регулярно правите Dockerfile руками или через агента.
Какие задачи решает
- разложить слои так, чтобы кэш не сбрасывался на каждой правке кода
- вынести сборку и рантайм в отдельные стадии
- убрать секреты из ARG и ENV
- подключить cache mount для npm, pip или apt
- проверить Dockerfile на антипаттерны перед мержем
Примеры запросов агенту
- Перепиши мой Dockerfile: вынеси зависимости в отдельный слой перед копированием исходников
- Разбей этот Dockerfile на build и runtime стадии, в финальный образ положи только артефакты
- Проверь Dockerfile на утечки секретов и добавь non-root пользователя
Как установить dockerfile-optimise
1Через Skills CLI (Vercel)
npx skills add pproenca/dot-skills --skill dockerfile-optimise -a claude-code2Вручную: положить файлы
~/.claude/skills/dockerfile-optimise/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/dockerfile-optimise/
1Через Skills CLI (Vercel)
npx skills add pproenca/dot-skills --skill dockerfile-optimise -a codex2Вручную: положить файлы
.agents/skills/dockerfile-optimise/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add pproenca/dot-skills --skill dockerfile-optimise -a cursor2Вручную: положить файлы
.cursor/skills/dockerfile-optimise/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install pproenca/dot-skills dockerfile-optimise2Вручную: положить файлы
.github/skills/dockerfile-optimise/SKILL.md1Через Skills CLI (Vercel)
npx skills add pproenca/dot-skills --skill dockerfile-optimise -a gemini-cli2Командой платформы
gemini skills install https://github.com/pproenca/dot-skills --path skills/.experimental/dockerfile-optimiseВручную: положить файлы
.devin/skills/dockerfile-optimise/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add pproenca/dot-skills --skill dockerfile-optimise -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о dockerfile-optimise
Как установить dockerfile-optimise в Claude?
Выполните npx skills add pproenca/dot-skills --skill dockerfile-optimise -a claude-code. Скилл появится в ~/.claude/skills/dockerfile-optimise/SKILL.md.
Что делает dockerfile-optimise?
Даёт агенту 48 правил оптимизации Dockerfile из официальной документации Docker: кэш слоёв, multi-stage, базовые образы, секреты, зависимости, инструкции и проверки.
Нужна ли директива syntax для работы правил?
Для cache mounts, secret mounts, heredocs и COPY --link — да, без неё эти возможности BuildKit не сработают. Остальные правила применяются и без неё.
Исходный текст
SKILL.md · MIT
--- name: dockerfile-optimise description: Dockerfile optimization guidelines from official Docker documentation. This skill should be used when writing, reviewing, or refactoring Dockerfiles to ensure optimal build time, image size, security, and robustness. Triggers on tasks involving Dockerfile creation, Docker image builds, container optimization, multi-stage builds, build cache, or Docker security hardening. --- # Dockerfile Optimization Best Practices Comprehensive Dockerfile optimization guide sourced exclusively from official Docker documentation. Contains 48 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation. ## When to Apply Reference these guidelines when: - Writing new Dockerfiles or modifying existing ones - Optimizing Docker build times (layer caching, cache mounts, context management) - Reducing Docker image size (multi-stage builds, minimal base images) - Hardening container security (secret mounts, non-root users, attestations) - Setting up CI/CD pipelines with Docker builds - Reviewing Dockerfiles for anti-patterns ## Rule Categories by Priority | Priority | Category | Impact | Prefix | |----------|----------|--------|--------| | 1 | Layer Caching & Ordering | CRITICAL | `cache-` | | 2 | Multi-Stage Builds | CRITICAL | `stage-` | | 3 | Base Image Selection | HIGH | `base-` | | 4 | Build Context Management | HIGH | `ctx-` | | 5 | Security & Secrets | HIGH | `sec-` | | 6 | Dependency Management | MEDIUM-HIGH | `dep-` | | 7 | Instruction Patterns | MEDIUM | `inst-` | | 8 | Quality & Validation | MEDIUM | `lint-` | ## Quick Reference ### 1. Layer Caching & Ordering (CRITICAL) - [`cache-layer-order`](references/cache-layer-order.md) - Order layers by change frequency - [`cache-copy-deps-first`](references/cache-copy-deps-first.md) - Copy dependency files before source code - [`cache-copy-link`](references/cache-copy-link.md) - Use COPY --link for cache-efficient layer copying - [`cache-mount-package`](references/cache-mount-package.md) - Use cache mounts for package managers - [`cache-apt-combine`](references/cache-apt-combine.md) - Combine apt-get update with install - [`cache-external`](references/cache-external.md) - Use external cache for CI/CD builds - [`cache-invalidation`](references/cache-invalidation.md) - Avoid unnecessary cache invalidation - [`cache-minimize-layers`](references/cache-minimize-layers.md) - Consolidate related RUN instructions ### 2. Multi-Stage Builds (CRITICAL) - [`stage-separate-build-runtime`](references/stage-separate-build-runtime.md) - Separate build and runtime stages - [`stage-named-stages`](references/stage-named-stages.md) - Use named build stages - [`stage-parallel-branches`](references/stage-parallel-branches.md) - Exploit parallel stage execution - [`stage-target-builds`](references/stage-target-builds.md) - Use target builds for dev/prod - [`stage-copy-artifacts-only`](references/stage-copy-artifacts-only.md) - Copy only final artifacts between stages - [`stage-reusable-base`](references/stage-reusable-base.md) - Create reusable base stages ### 3. Base Image Selection (HIGH) - [`base-minimal-image`](references/base-minimal-image.md) - Use minimal base images - [`base-official-images`](references/base-official-images.md) - Use Docker Official Images - [`base-pin-versions`](references/base-pin-versions.md) - Pin base image versions with digests - [`base-arg-version`](references/base-arg-version.md) - Use ARG before FROM to parameterize base images - [`base-rebuild-regularly`](references/base-rebuild-regularly.md) - Rebuild images regularly with --pull - [`base-distroless`](references/base-distroless.md) - Use distroless or scratch images for production ### 4. Build Context Management (HIGH) - [`ctx-dockerignore`](references/ctx-dockerignore.md) - Use .dockerignore to exclude unnecessary files - [`ctx-bind-mounts`](references/ctx-bind-mounts.md) - Use bind mounts instead of COPY for build-only files - [`ctx-minimize-context`](references/ctx-minimize-context.md) - Keep build context small - [`ctx-syntax-directive`](references/ctx-syntax-directive.md) - Use syntax directive for latest BuildKit features (prerequisite for cache mounts, secret mounts, heredocs, COPY --link) ### 5. Security & Secrets (HIGH) - [`sec-secret-mounts`](references/sec-secret-mounts.md) - Use secret mounts for sensitive data - [`sec-non-root-user`](references/sec-non-root-user.md) - Run as non-root user - [`sec-no-secrets-in-args`](references/sec-no-secrets-in-args.md) - Never pass secrets via ARG or ENV - [`sec-ssh-mounts`](references/sec-ssh-mounts.md) - Use SSH mounts for private repository access - [`sec-attestations`](references/sec-attestations.md) - Enable SBOM and provenance attestations - [`sec-no-unnecessary-packages`](references/sec-no-unnecessary-packages.md) - Avoid installing unnecessary packages - [`sec-ephemeral-containers`](references/sec-ephemeral-containers.md) - Design ephemeral, stateless containers ### 6. Dependency Management (MEDIUM-HIGH) - [`dep-cache-mount-apt`](references/dep-cache-mount-apt.md) - Use cache mount for apt package manager - [`dep-cache-mount-npm`](references/dep-cache-mount-npm.md) - Use cache mount for npm, yarn, and pnpm - [`dep-cache-mount-pip`](references/dep-cache-mount-pip.md) - Use cache mount for pip - [`dep-version-pin`](references/dep-version-pin.md) - Pin package versions for reproducibility - [`dep-cleanup-caches`](references/dep-cleanup-caches.md) - Clean package manager caches in the same layer ### 7. Instruction Patterns (MEDIUM) - [`inst-json-cmd`](references/inst-json-cmd.md) - Use JSON form for CMD and ENTRYPOINT - [`inst-healthcheck`](references/inst-healthcheck.md) - Define HEALTHCHECK for container orchestration - [`inst-heredoc-scripts`](references/inst-heredoc-scripts.md) - Use heredocs for multi-line scripts - [`inst-entrypoint-exec`](references/inst-entrypoint-exec.md) - Use exec in entrypoint scripts - [`inst-workdir-absolute`](references/inst-workdir-absolute.md) - Use absolute paths with WORKDIR - [`inst-copy-over-add`](references/inst-copy-over-add.md) - Prefer COPY over ADD ### 8. Quality & Validation (MEDIUM) - [`lint-build-checks`](references/lint-build-checks.md) - Enable Docker build checks - [`lint-pipefail`](references/lint-pipefail.md) - Use pipefail for piped RUN commands - [`lint-labels`](references/lint-labels.md) - Use standard labels for image metadata - [`lint-sort-arguments`](references/lint-sort-arguments.md) - Sort multi-line arguments alphabetically - [`lint-single-concern`](references/lint-single-concern.md) - One concern per container ## How to Use Read individual reference files for detailed explanations and code examples: - [Section definitions](references/_sections.md) - Category structure and impact levels - [Rule template](assets/templates/_template.md) - Template for adding new rules ## Reference Files | File | Description | |------|-------------| | [references/_sections.md](references/_sections.md) | Category definitions and ordering | | [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules | | [metadata.json](metadata.json) | Version and reference information |
© pproenca · MIT · pproenca/dot-skills