Bake 目标
目录
Bake 文件中的目标代表一次构建调用。它包含您通常会使用标志传递给docker build
命令的所有信息。
target "webapp" {
dockerfile = "webapp.Dockerfile"
tags = ["docker.io/username/webapp:latest"]
context = "https://github.com/username/webapp"
}
要使用 Bake 构建目标,请将目标名称传递给bake
命令。
$ docker buildx bake webapp
您可以通过将多个目标名称传递给bake
命令来同时构建多个目标。
$ docker buildx bake webapp api tests
默认目标
如果您在运行docker buildx bake
时未指定目标,Bake 将构建名为default
的目标。
target "default" {
dockerfile = "webapp.Dockerfile"
tags = ["docker.io/username/webapp:latest"]
context = "https://github.com/username/webapp"
}
要构建此目标,请运行docker buildx bake
而不带任何参数。
$ docker buildx bake
目标属性
您可以为目标设置的属性与docker build
的 CLI 标志非常相似,还有一些特定于 Bake 的附加属性。
有关您可以为目标设置的所有属性,请参阅Bake 参考。
目标分组
您可以使用group
块将目标组合在一起。当您想一次构建多个目标时,这很有用。
group "all" {
targets = ["webapp", "api", "tests"]
}
target "webapp" {
dockerfile = "webapp.Dockerfile"
tags = ["docker.io/username/webapp:latest"]
context = "https://github.com/username/webapp"
}
target "api" {
dockerfile = "api.Dockerfile"
tags = ["docker.io/username/api:latest"]
context = "https://github.com/username/api"
}
target "tests" {
dockerfile = "tests.Dockerfile"
contexts = {
webapp = "target:webapp",
api = "target:api",
}
output = ["type=local,dest=build/tests"]
context = "."
}
要构建组中的所有目标,请将组的名称传递给bake
命令。
$ docker buildx bake all
其他资源
请参阅以下页面以了解有关 Bake 功能的更多信息