{"id":"70ab2a2cfeb2c644","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 %s","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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/create.go#L184-L220","documentation":"newCIDFile, used by `docker run`/`docker create` with the --cidfile flag, refuses to write the container ID if the target file already exists (os.Stat succeeds). This is a deliberate safety guard: an existing cidfile likely belongs to a still-running or previously created container, and silently overwriting it could orphan that container's tracking.","triggerScenarios":"`docker run --cidfile /path/to/pid.cid ...` or `docker create --cidfile ...` where the file at that path already exists — typically left over from a prior run that was not cleaned up.","commonSituations":"Init scripts or systemd units that use --cidfile but do not delete the file on container stop; re-running a failed script; two services accidentally configured with the same cidfile path.","solutions":["Delete the stale file after confirming the previous container is stopped/removed: `rm /path/to/file.cid`.","Add cleanup to your service/script lifecycle (e.g. ExecStopPost=/bin/rm -f %t/app.cid in systemd).","Use a unique cidfile path per invocation, or check `docker ps` for a container matching the ID in the file before removing it."],"exampleFix":"# before\ndocker run --cidfile /run/app.cid myimage   # fails: file exists\n# after\ndocker rm -f \"$(cat /run/app.cid)\" 2>/dev/null; rm -f /run/app.cid\ndocker run --cidfile /run/app.cid myimage","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","docker-run","cidfile","lifecycle"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}