{"record":{"id":"b128eb629eeeb089","repo":"dagger/dagger","slug":"create-container-hosts-tmp-file-w","errorCode":null,"errorMessage":"create container hosts tmp file: %w","messagePattern":"create container hosts tmp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/engineutil/executor_spec.go","lineNumber":290,"sourceCode":"\n\tif len(state.execMD.HostAliases) == 0 {\n\t\treturn nil\n\t}\n\n\tbaseHostsFile, err := os.Open(state.hostsFilePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open base hosts file: %w\", err)\n\t}\n\tdefer baseHostsFile.Close()\n\n\tbaseHostsStat, err := baseHostsFile.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"stat base hosts file: %w\", err)\n\t}\n\n\tctrHostsFile, err := os.CreateTemp(\"\", \"hosts\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create container hosts tmp file: %w\", err)\n\t}\n\tdefer ctrHostsFile.Close()\n\tstate.hostsFilePath = ctrHostsFile.Name()\n\tstate.cleanups.Add(\"remove hosts file\", func() error {\n\t\treturn os.RemoveAll(state.hostsFilePath)\n\t})\n\n\tif err := ctrHostsFile.Chmod(baseHostsStat.Mode().Perm()); err != nil {\n\t\treturn fmt.Errorf(\"chmod hosts file: %w\", err)\n\t}\n\n\tif _, err := io.Copy(ctrHostsFile, baseHostsFile); err != nil {\n\t\treturn fmt.Errorf(\"copy base hosts file: %w\", err)\n\t}\n\n\tfor target, aliases := range state.execMD.HostAliases {\n\t\tvar ips []net.IP\n\t\tvar errs error","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/engineutil/executor_spec.go#L272-L308","documentation":"setupNetwork creates the container's hosts file via os.CreateTemp(\"\", \"hosts\") before copying in the base content and host aliases. This error wraps CreateTemp failure, meaning no temp hosts file could be created in the OS temp directory, aborting network setup.","triggerScenarios":"os.CreateTemp(\"\", \"hosts\") fails: TMPDIR//tmp missing, read-only, or full; process lacks write permission on the temp dir.","commonSituations":"Read-only /tmp in hardened containers or distroless-like images; disk-full nodes; TMPDIR pointing at a non-existent path; restrictive security profiles blocking temp file creation.","solutions":["Confirm the temp directory exists and is writable: `touch $TMPDIR/probe && rm $TMPDIR/probe`.","Free disk space or relocate TMPDIR to a writable volume.","Fix permissions on the temp dir for the engine's user.","Inspect the wrapped cause with errors.Is/As (fs.ErrNotExist, fs.ErrPermission) to pinpoint the case."],"exampleFix":"// before: read-only root filesystem, no writable /tmp\ndocker run --read-only myengine\n// after: mount a writable tmpfs\n docker run --read-only --tmpfs /tmp:rw,size=64m myengine","handlingStrategy":"validation","validationCode":"// precheck temp dir before engine start\nprobe := filepath.Join(os.TempDir(), \".hostsprobe\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil {\n\treturn fmt.Errorf(\"cannot create temp files in %s: %w\", os.TempDir(), err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tif errors.Is(err, fs.ErrNotExist) {\n\t\t// create TMPDIR or unset it to fall back to /tmp\n\t} else if errors.Is(err, fs.ErrPermission) {\n\t\t// fix dir permissions or run with proper uid\n\t}\n\treturn fmt.Errorf(\"hosts temp file: %w\", err)\n}","preventionTips":["Mount a writable tmpfs at /tmp in read-only-root containers.","Set TMPDIR explicitly to a writable volume in hardened environments.","Alert on temp-volume disk-full conditions."],"tags":["filesystem","temp-file","hosts-file","io"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}