关于 docker-hadolint
面向维护 Docker 镜像的开发者,提供 Dockerfile 编写与检查指南。内容指定固定版本的 Hadolint,并介绍 BuildKit 和镜像构建实践。
主要功能
- 01固定使用 Hadolint v2.15.1
- 02通过 Docker 或 Makefile 检查 Dockerfile
- 03BuildKit 缓存挂载指南
- 04BuildKit 密钥处理指南
- 05多阶段与 distroless 镜像指南
适用场景
- 01使用 Hadolint 验证 Dockerfile
- 02在镜像构建中应用缓存挂载
- 03避免构建密钥进入最终镜像
- 04拆分构建阶段与运行阶段
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ thebeardedbearsas/ claude-craft --skill docker-hadolint安装后在 Claude Code 中输入/docker-hadolint确认已加载。
详细介绍
Docker 和 Hadolint(2026)
版本(2026 年 10 月)
- Docker Engine:29.9.0
来源:https://docs.docker.com/engine/release-notes/29/ - Docker Compose:5.6.0(
version:字段已弃用,不应再编写)
来源:https://github.com/docker/compose/releases - Hadolint:v2.15.1(固定的稳定版本)
来源:https://github.com/hadolint/hadolint/releases/tag/v2.15.1
Hadolint 验证
始终使用固定版本 v2.15.1(绝不使用 latest 或不带标签的版本)。
# Validation Dockerfile
docker run --rm -i hadolint/hadolint:v2.15.1 < Dockerfile
# Validation via Makefile (recommandé)
make hadolint
2026 年最佳实践
BuildKit 缓存挂载
RUN --mount=type=cache,target=/var/cache/apk \
apk add --no-cache postgresql-dev
优势:构建时间缩短 40-60%
来源:https://docs.docker.com/build/cache/
BuildKit 密钥
RUN --mount=type=secret,id=composer_token \
COMPOSER_AUTH="$(cat /run/secrets/composer_token)" composer install
优势:最终镜像中不包含任何密钥
来源:https://docs.docker.com/build/building/secrets/
多阶段构建
FROM php:8.4-fpm-alpine AS builder
RUN composer install
FROM php:8.4-fpm-alpine AS runtime
COPY --from=builder /app /app
优势:镜像大小缩小 60-97%
来源:https://docs.docker.com/build/building/multi-stage/
Distroless 镜像
FROM gcr.io/distroless/php8.4-fpm
COPY --from=builder /app /app
优势:攻击面最小化,CVE 数量减少 90%
来源:https://github.com/GoogleContainerTools/distroless
完整文档
查看 @.claude/references/symfony/docker.md,了解完整架构和示例。
评论
支持 Markdown