{"record":{"id":"fe7054328a39f6aa","repo":"docker/cli","slug":"failed-to-create-the-container-id-file-w","errorCode":null,"errorMessage":"failed to create the container ID file: %w","messagePattern":"failed to create the container ID file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/create.go","lineNumber":207,"sourceCode":"\t}\n\tif _, err := cid.file.WriteString(id); err != nil {\n\t\treturn fmt.Errorf(\"failed to write the container ID (%s) to file: %w\", id, err)\n\t}\n\tcid.written = true\n\treturn nil\n}\n\nfunc newCIDFile(cidPath string) (*cidFile, error) {\n\tif cidPath == \"\" {\n\t\treturn &cidFile{}, nil\n\t}\n\tif _, err := os.Stat(cidPath); err == nil {\n\t\treturn nil, errors.New(\"container ID file found, make sure the other container isn't running or delete \" + cidPath)\n\t}\n\n\tf, err := os.Create(cidPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create the container ID file: %w\", err)\n\t}\n\n\treturn &cidFile{path: cidPath, file: f}, nil\n}\n\n//nolint:gocyclo\nfunc createContainer(ctx context.Context, dockerCLI command.Cli, containerCfg *containerConfig, options *createOptions) (containerID string, _ error) {\n\tconfig := containerCfg.Config\n\thostConfig := containerCfg.HostConfig\n\tnetworkingConfig := containerCfg.NetworkingConfig\n\n\tvar namedRef reference.Named\n\n\t// TODO(thaJeztah): add a platform option-type / flag-type.\n\tif options.platform != \"\" {\n\t\tif _, err := platforms.Parse(options.platform); err != nil {\n\t\t\treturn \"\", err\n\t\t}","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/create.go#L189-L225","documentation":"Returned by newCIDFile when os.Create(cidPath) fails while setting up the CID file for --cidfile (cli/command/container/create.go:205-207). This runs before any daemon call. Common os.Create failures: parent directory missing (ENOENT), permission denied (EACCES), or an existing path component is not a directory (ENOTDIR). Note a pre-existing file at cidPath is caught earlier (line 201-203) with a distinct 'container ID file found' message.","triggerScenarios":"Running docker create/run --cidfile <path> where the parent directory does not exist, is not writable, or the path is otherwise invalid for file creation. The error short-circuits container creation.","commonSituations":"Typo in path, missing parent directory, permission denied, read-only filesystem, or a path that traverses a file as if it were a directory.","solutions":["Create the parent directory first: mkdir -p $(dirname <path>).","Use a writable location such as /tmp or the project dir.","Fix permissions on the target directory: chmod u+w <dir>.","Ensure the path does not already exist (a pre-existing file yields a different, earlier error)."],"exampleFix":"# before\ndocker create --cidfile /var/run/no-such-dir/cid myimage   # parent missing\n# after\nmkdir -p /tmp/cids && docker create --cidfile /tmp/cids/cid myimage","handlingStrategy":"validation","validationCode":"// Validate the --cidfile path can be created before invoking docker create.\nfunc validateCidPath(path string) error {\n    dir := filepath.Dir(path)\n    if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {\n        return fmt.Errorf(\"cidfile parent dir %s missing or not a directory\", dir)\n    }\n    if _, err := os.Stat(path); err == nil {\n        return errors.New(\"cidfile already exists; remove it first\")\n    }\n    // try a probe create/remove\n    f, err := os.Create(path)\n    if err != nil { return err }\n    f.Close(); os.Remove(path)\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["mkdir -p the parent directory before using --cidfile.","Use an absolute, writable path under /tmp or the project dir.","Ensure the path does not already exist from a prior run."],"tags":["container","cidfile","filesystem","permissions"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}