{"record":{"id":"20bba00591963c57","repo":"docker/cli","slug":"label-file-w","errorCode":null,"errorMessage":"--label-file: %w","messagePattern":"--label-file: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":515,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\tdeviceMapping, err := parseDevice(validated, serverOS)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdeviceMappings = append(deviceMappings, deviceMapping)\n\t}\n\n\t// collect all the environment variables for the container\n\tenvVariables, err := opts.ReadKVEnvStrings(copts.envFile.GetSlice(), copts.env.GetSlice())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"--env-file: %w\", err)\n\t}\n\n\t// collect all the labels for the container\n\tlabels, err := opts.ReadKVStrings(copts.labelsFile.GetSlice(), copts.labels.GetSlice())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"--label-file: %w\", err)\n\t}\n\n\tpidMode := container.PidMode(copts.pidMode)\n\tif !pidMode.Valid() {\n\t\treturn nil, errors.New(\"--pid: invalid PID mode\")\n\t}\n\n\tutsMode := container.UTSMode(copts.utsMode)\n\tif !utsMode.Valid() {\n\t\treturn nil, errors.New(\"--uts: invalid UTS mode\")\n\t}\n\n\tusernsMode := container.UsernsMode(copts.usernsMode)\n\tif !usernsMode.Valid() {\n\t\treturn nil, errors.New(\"--userns: invalid USER mode\")\n\t}\n\n\tcgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode)","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L497-L533","documentation":"Returned in opts.go:515 when opts.ReadKVStrings fails while reading --label-file entries (combined with inline --label values). The wrapped %w carries the file or parse error.","triggerScenarios":"`docker run --label-file <path>` where the file is missing/unreadable or a label line is malformed (labels must be KEY=VALUE).","commonSituations":"Wrong path, permission denied, a line missing the `=` or with an invalid key, or encoding issues.","solutions":["Verify the file exists and is readable.","Ensure each line is KEY=VALUE with a valid label key (dotted/segmented keys allowed, value optional).","Fix encoding/line endings."],"exampleFix":"# before: labels.list contains 'com.example.role' (no =)\ndocker run --label-file labels.list alpine\n\n# after: labels.list contains 'com.example.role=web'\ndocker run --label-file labels.list alpine","handlingStrategy":"validation","validationCode":"// Validate label-file lines are KEY=VALUE (value optional) before docker:\nfor _, p := range labelFiles {\n    f, err := os.Open(p)\n    if err != nil { return fmt.Errorf(\"label-file unreadable: %w\", err) }\n    defer f.Close()\n    sc := bufio.NewScanner(f)\n    for sc.Scan() {\n        line := strings.TrimSpace(sc.Text())\n        if line == \"\" || strings.HasPrefix(line, \"#\") { continue }\n        if !strings.Contains(line, \"=\") { return fmt.Errorf(\"bad label line: %q\", line) }\n    }\n}","typeGuard":null,"tryCatchPattern":"// Deterministic file error; fix the file, do not retry.\nif err != nil && strings.Contains(err.Error(), \"--label-file\") {\n    /* surface offending file/line */\n}","preventionTips":["Ensure each line is KEY=VALUE.\nCheck path and permissions.\nValidate in config-generation tooling."],"tags":["container","labels","filesystem","flag-validation","create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}