Bake 目標
目錄
Bake 檔案中的目標表示一次構建呼叫。它包含您通常透過標誌傳遞給 `docker build` 命令的所有資訊。
docker-bake.hcl
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` 的目標。
docker-bake.hcl
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` 塊將目標分組。當您想一次構建多個目標時,這非常有用。
docker-bake.hcl
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 功能的更多資訊