| --build-arg | 向 Dockerfile ARG 传值,可多次出现 |
|---|---|
| --target | 只构建到指定阶段(调 SDK 环境失败时定位中间层) |
| --no-cache | 忽略缓存全量重建(怀疑缓存污染时) |
| -f | 指定其他 Dockerfile 文件(默认上下文根 Dockerfile) |
| --platform | 指定目标平台,多架构需 buildx |
典型组合
典型组合
docker build \
--build-arg NPM_REGISTRY=https://registry.npmmirror.com \
--target build \
--no-cache \
-t app:dev \
-f docker/Dockerfile .上下文是命令最后一个参数(通常 .);-f 指定的 Dockerfile 不必在上下文根,但只能引用上下文内的文件。