{"record":{"id":"77c4f31c93ed34b7","repo":"docker/cli","slug":"failed-to-write-the-container-id-s-to-file-w","errorCode":null,"errorMessage":"failed to write the container ID (%s) to file: %w","messagePattern":"failed to write the container ID \\((.+?)\\) to file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/create.go","lineNumber":191,"sourceCode":"\t}\n\t_ = cid.file.Close()\n\n\tif cid.written {\n\t\treturn nil\n\t}\n\tif err := os.Remove(cid.path); err != nil && !errors.Is(err, os.ErrNotExist) {\n\t\treturn fmt.Errorf(\"failed to remove the CID file: %w\", err)\n\t}\n\n\treturn nil\n}\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","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/create.go#L173-L209","documentation":"Returned by cidFile.Write(id) when writing the container ID string to the already-created CID file fails (cli/command/container/create.go:190-192). The file was opened by os.Create in newCIDFile; a write failure after the container was successfully created (ENOSPC, EROFS, EIO, or the fd invalidated) is wrapped with the actual ID that could not be persisted.","triggerScenarios":"Using --cidfile <path>, the container is created and Write(id) is invoked, but file.WriteString(id) fails. The container exists on the daemon, but the ID could not be recorded to disk.","commonSituations":"Disk full (ENOSPC) on the volume holding the CID file, the filesystem remounted read-only, a network filesystem write error, or the file descriptor invalidated (e.g. file deleted and reopened weirdly by an external tool).","solutions":["Free disk space on the target volume and retry.","Point --cidfile at a local, writable filesystem (not a near-full or read-only mount).","Record the container ID printed by the daemon by other means if the CID file cannot be written.","Ensure no external tooling locks/deletes the CID file mid-run."],"exampleFix":"# before\ndocker create --cidfile /full-disk/cid myimage   # write fails: ENOSPC\n# after\ndocker create --cidfile /tmp/cid myimage","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := cidFile.Write(id); err != nil {\n    // container was created; record id via fallback (e.g. log) since the file write failed\n}","preventionTips":["Ensure adequate free space on the volume holding the CID file.","Use a local writable filesystem for --cidfile.","Have a fallback to capture the printed container ID if the file write fails."],"tags":["container","cidfile","filesystem","disk-space","io"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}