{"record":{"id":"f42d7da4c696cad6","repo":"docker/cli","slug":"removing-image-id-file-w","errorCode":null,"errorMessage":"removing image ID file: %w","messagePattern":"removing image ID file: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/image/build.go","lineNumber":224,"sourceCode":"\t}\n\n\tif options.dockerfileFromStdin() {\n\t\tif contextType == build.ContextTypeStdin {\n\t\t\treturn errors.New(\"invalid argument: can't use stdin for both build context and dockerfile\")\n\t\t}\n\t\tdockerfileCtx = dockerCli.In()\n\t}\n\n\tprogBuff = dockerCli.Out()\n\tbuildBuff = dockerCli.Out()\n\tif options.quiet {\n\t\tprogBuff = bytes.NewBuffer(nil)\n\t\tbuildBuff = bytes.NewBuffer(nil)\n\t}\n\tif options.imageIDFile != \"\" {\n\t\t// Avoid leaving a stale file if we eventually fail\n\t\tif err := os.Remove(options.imageIDFile); err != nil && !os.IsNotExist(err) {\n\t\t\treturn fmt.Errorf(\"removing image ID file: %w\", err)\n\t\t}\n\t}\n\n\tswitch contextType {\n\tcase build.ContextTypeStdin:\n\t\t// buildCtx is tar archive. if stdin was dockerfile then it is wrapped\n\t\tbuildCtx, relDockerfile, err = build.GetContextFromReader(dockerCli.In(), options.dockerfileName)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to prepare context from STDIN: %w\", err)\n\t\t}\n\tcase build.ContextTypeLocal:\n\t\tcontextDir, relDockerfile, err = build.GetContextFromLocalDir(options.context, options.dockerfileName)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to prepare context: %s\", err)\n\t\t}\n\t\tif strings.HasPrefix(relDockerfile, \"..\"+string(filepath.Separator)) {\n\t\t\t// Dockerfile is outside build-context; read the Dockerfile and pass it as dockerfileCtx\n\t\t\tdockerfileCtx, err = os.Open(options.dockerfileName)","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/image/build.go#L206-L242","documentation":"Returned by runBuild (build.go:224) when os.Remove(options.imageIDFile) fails with an error other than os.IsNotExist, while trying to clear a stale --iidfile before the build starts. The pre-removal is intentional (to avoid writing a stale ID if the build later fails), so a failure here means the file exists but cannot be removed.","triggerScenarios":"Running 'docker build --iidfile <path>' where <path> exists and the current user lacks permission to delete it, or the parent directory does not permit removal (read-only mount, immutable file, SELinux denial, or the path is a directory).","commonSituations":"CI workspace where a previous run created the iidfile as root and the current run is non-root; the iidfile path points into a read-only bind-mount; the path collides with a directory name; NFS/SELinux denying unlink.","solutions":["Delete or fix permissions on the existing file: 'rm -f <path>' or 'chmod u+w <path>'.","Point --iidfile to a writable location owned by the current user.","Ensure the CI agent runs builds as the same user that owns the output directory.","Check for SELinux/AppArmor denials in the system journal if permissions look correct."],"exampleFix":"# before\ndocker build --iidfile /tmp/builds/id .\n# /tmp/builds/id owned by root, current user cannot remove\n# after\nrm -f /tmp/builds/id\ndocker build --iidfile /tmp/builds/id .","handlingStrategy":"validation","validationCode":"// Ensure the iidfile path is removable before building.\nfunc ensureIidfileWritable(path string) error {\n\tif err := os.Remove(path); err != nil && !os.IsNotExist(err) {\n\t\treturn err\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := buildCmd.Execute(); err != nil {\n\tif strings.Contains(err.Error(), \"removing image ID file\") {\n\t\t// fix permissions on the existing iidfile, then re-run\n\t}\n}","preventionTips":["Point --iidfile to a writable, user-owned location.","Run CI builds as the same user that owns the output directory.","Pre-clean stale iidfiles at the start of the build script."],"tags":["build","iidfile","permissions","filesystem"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}