{"record":{"id":"e6782b90c7d877dc","repo":"docker/compose","slug":"label-must-be-set-as-key-value","errorCode":null,"errorMessage":"label must be set as KEY=VALUE","messagePattern":"label must be set as KEY=VALUE","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/run.go","lineNumber":306,"sourceCode":"\tproject, err := options.apply(project)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\terr = createOpts.Apply(project)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := checksForRemoteStack(ctx, dockerCli, project, buildOpts, createOpts.AssumeYes, []string{}); err != nil {\n\t\treturn err\n\t}\n\n\tlabels := types.Labels{}\n\tfor _, s := range options.labels {\n\t\tkey, val, ok := strings.Cut(s, \"=\")\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"label must be set as KEY=VALUE\")\n\t\t}\n\t\tlabels[key] = val\n\t}\n\n\tvar buildForRun *api.BuildOptions\n\tif !createOpts.noBuild {\n\t\tbo, err := buildOpts.toAPIBuildOptions(nil)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tbuildForRun = &bo\n\t}\n\n\tenvironment, err := options.getEnvironment(project.Environment.Resolve)\n\tif err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/run.go#L288-L324","documentation":"Each `--label` argument to `docker compose run` must be a KEY=VALUE pair. The parsing loop uses strings.Cut on the first '='; if the argument contains no '=' at all the error is returned immediately (empty values like KEY= are allowed and become an empty label value).","triggerScenarios":"Running `docker compose run --label com.example.tag web` (missing =VALUE), or quoting errors that strip the `=value` part, e.g. `--label \"com.example.tag\"` where the value ended up in a separate argv slot.","commonSituations":"Passing labels from unquoted/unset variables (`--label mylabel=${TAG}` is fine when set, but building the whole KEY=VALUE by concatenation can drop the '=' part); habits from `docker run --label key value` (space form) which compose does not accept.","solutions":["Write labels as `--label KEY=VALUE`, e.g. `--label com.example.owner=alice`.","Quote the whole pair in one argv token: `--label \"key=$VALUE\"`.","Remember `--label` is repeatable — one flag per label, not a comma-separated list."],"exampleFix":"# before\ndocker compose run --label com.example.owner alice web\n\n# after\ndocker compose run --label com.example.owner=alice web","handlingStrategy":"validation","validationCode":"# bash: validate each label is KEY=VALUE\nfor l in \"${LABELS[@]}\"; do\n  [[ \"$l\" == *=* ]] || { echo \"label must be KEY=VALUE: '$l'\" >&2; exit 2; }\ndone\ndocker compose run \"${LABELS[@]/#/--label }\" web","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote each pair as one token: --label \"key=$VALUE\".","One --label flag per label; empty values (KEY=) are legal but the '=' is mandatory."],"tags":["cli","run","labels","flags","parsing"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}