{"record":{"id":"3c27de29c3b32e6a","repo":"docker/cli","slug":"container-id-file-found-make-sure-the-other-conta","errorCode":null,"errorMessage":"container ID file found, make sure the other container isn't running or delete ${cidPath}","messagePattern":"container ID file found, make sure the other container isn't running or delete (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/create.go","lineNumber":202,"sourceCode":"}\n\nfunc (cid *cidFile) Write(id string) error {\n\tif cid.file == nil {\n\t\treturn nil\n\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","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/create.go#L184-L220","documentation":"newCIDFile (cli/command/container/create.go:197) handles the --cidfile option. At line 201-202, if os.Stat(cidPath) succeeds (the file already exists), it returns errors.New(\"container ID file found, make sure the other container isn't running or delete \" + cidPath). The CID file mechanism writes the new container's ID to a file; a pre-existing file suggests a prior container created with that same --cidfile may still be alive, so creation is refused to avoid ambiguity.","triggerScenarios":"Running `docker create --cidfile /path/to/id <image>` when /path/to/id already exists on disk. Triggered by re-running a create command that previously wrote the file without cleanup, or by a leftover file from a still-running container.","commonSituations":"Re-running a script after a partial failure that left the CID file; the previous container still running; static CID file paths in automation; container created with --cidfile then not removed.","solutions":["Verify whether the prior container is still needed: `docker ps -a` and check its ID against the file's contents.","If the old container is stale, remove it and delete the file: `docker rm <id>; rm <cidfile>`.","If it's safe, just delete the CID file: `rm <cidfile>`.","Use unique CID file paths per run (e.g. mktemp) in automation to avoid collisions."],"exampleFix":"# before — leftover file blocks creation\ndocker create --cidfile ./web.cid nginx\n# after — confirm nothing uses it, then remove\n# cat ./web.cid  # check; docker ps -a --filter id=$(cat ./web.cid)\nrm -f ./web.cid\ndocker create --cidfile ./web.cid nginx","handlingStrategy":"validation","validationCode":"// Before create, check the CID file and clean up if safe:\nif cidPath != \"\" {\n    if _, err := os.Stat(cidPath); err == nil {\n        // confirm no live container uses it, then remove\n        _ = os.Remove(cidPath)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := createContainer(ctx, cli, cfg, opts); err != nil {\n    if strings.Contains(err.Error(), \"container ID file found\") {\n        // inspect prior container, remove if stale, delete the CID file, then retry\n    }\n    return err\n}","preventionTips":["Use unique CID file paths per run (e.g. mktemp) in automation.","Clean up CID files when their containers are removed.","Check `docker ps -a` against the file contents before deleting a leftover CID file."],"tags":["container","create","cidfile","filesystem","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}