Skip to content
Latchkey

Docker "buildx bake: target ... not defined in any group" in CI

You ran docker buildx bake <name> but <name> is not a target or group defined in the bake file. Bake only builds targets it can find in docker-bake.hcl/.json, so an unknown name fails immediately.

What this error means

A docker buildx bake api fails with target api is not defined (or no such file or directory for the bake file). Nothing builds because bake cannot resolve the requested target.

docker buildx bake output
ERROR: target "api" is not defined in any group
# or, when the bake file itself is missing:
ERROR: failed to read docker-bake.hcl: no such file or directory

Common causes

The target/group name is misspelled or undefined

The name passed to bake must match a target "<name>" or group "<name>" block. A typo or a renamed target makes it undefined.

The bake file is not where bake looks

Bake reads docker-bake.hcl/docker-bake.json/compose from the current directory by default. Running from elsewhere, or a non-default filename without -f, means it finds no definitions.

The default group does not include the target

Running bake with no arguments builds the default group. A target outside that group is not built unless named explicitly or added to the group.

How to fix it

Name a defined target or pass the bake file

List the available targets and reference one, pointing -f at the file if needed.

Terminal
docker buildx bake -f docker-bake.hcl --print   # shows all targets/groups
docker buildx bake -f docker-bake.hcl api

Add the target to the default group

Define the target and include it in default so a bare bake builds it.

docker-bake.hcl
group "default" {
  targets = ["api", "web"]
}
target "api" {
  context = "./api"
}

How to prevent it

  • Run docker buildx bake --print in CI to validate targets before building.
  • Keep the bake file at the default path or always pass -f.
  • Reference targets via a single source of truth to avoid name drift.

Frequently asked questions

What causes ""target not defined""?
The name passed to bake must match a target "<name>" or group "<name>" block. A typo or a renamed target makes it undefined.
How do I fix "target not defined"?
List the available targets and reference one, pointing -f at the file if needed.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card