rmdir.cn

docker build

构建镜像

语法

docker build [选项] <构建上下文>

说明

从 Dockerfile 构建自定义镜像。支持多种构建选项和参数。

参数

  • -t

    为镜像指定名称和标签

  • -f

    指定 Dockerfile 路径

  • --no-cache

    不使用缓存构建

  • --build-arg

    传递构建参数

  • --platform

    指定目标平台

示例

基本构建

从当前目录构建镜像

docker build -t my-app:latest .

指定 Dockerfile

使用指定的 Dockerfile 构建

docker build -t my-app -f Dockerfile.prod .

传递构建参数

构建时传递参数

docker build --build-arg NODE_ENV=production -t my-app .