{"record":{"id":"d4b4bdf31ff227cc","repo":"dagger/dagger","slug":"replace-nameservers-w","errorCode":null,"errorMessage":"replace nameservers: %w","messagePattern":"replace nameservers: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"network/netinst/resolvconf.go","lineNumber":22,"sourceCode":"\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n\t\"syscall\"\n)\n\nconst resolv = \"/etc/resolv.conf\"\n\nfunc InstallResolvconf(name, containerDNS string) error {\n\tcontainerDNSResolv := containerResolvPath(name)\n\tif err := createIfNeeded(containerDNSResolv); err != nil {\n\t\treturn err\n\t}\n\n\t// create the resolv.conf for the container namespace by swapping out the\n\t// nameservers from the original, keeping any options and search domains\n\tif err := replaceNameservers(containerDNS, containerDNSResolv); err != nil {\n\t\treturn fmt.Errorf(\"replace nameservers: %w\", err)\n\t}\n\n\tif err := createIfNeeded(upstreamResolvPath); err != nil {\n\t\treturn err\n\t}\n\n\t// preserve original resolv.conf at upstream path\n\t//\n\t// if resolv.conf is bind mounted, its source will be bind mounted here\n\tif err := syscall.Mount(resolv, upstreamResolvPath, \"\", syscall.MS_BIND, \"\"); err != nil {\n\t\treturn fmt.Errorf(\"remount /etc/resolv.conf to upstream alias: %w\", err)\n\t}\n\n\t// mount container resolv.conf over /etc/resolv.conf\n\tif err := syscall.Mount(containerDNSResolv, resolv, \"\", syscall.MS_BIND|syscall.MS_RDONLY, \"\"); err != nil {\n\t\treturn fmt.Errorf(\"mount over /etc/resolv.conf: %w\", err)\n\t}\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/network/netinst/resolvconf.go#L4-L40","documentation":"InstallResolvconf sets up the DNS resolver for a new network namespace: it reads the host's /etc/resolv.conf and writes a copy whose nameserver lines are replaced with the container DNS address. This error wraps any failure from replaceNameservers — typically inability to open/read the host /etc/resolv.conf or to create/write the container's resolv.conf file. It is a privileged setup step, so failures usually mean filesystem or permission problems in the target namespace.","triggerScenarios":"Calling InstallResolvconf (via setupNetwork) when the host /etc/resolv.conf cannot be opened, when the container resolv.conf path (containerResolvPath(name)) cannot be created/written (O_WRONLY|O_CREATE|O_TRUNC with mode 0600 fails), or when the final dst.Close() flush fails (e.g. disk full).","commonSituations":"Missing or restricted /etc/resolv.conf in the environment performing netinst setup (restricted containers, minimal initramfs); read-only or full filesystem for the container DNS resolv path; wrong network namespace name producing an unwritable path; SELinux/AppArmor denying writes.","solutions":["Verify /etc/resolv.conf exists and is readable in the process performing setup (cat /etc/resolv.conf); if it is a dangling symlink, fix or create it","Check write permissions and space for the container resolv.conf path returned by containerResolvPath(name)","Run the setup with sufficient privileges (CAP_SYS_ADMIN / root) so the file and later mounts succeed","Inspect the wrapped underlying error (%w) in the message — it names the exact failing file operation"],"exampleFix":"// before\nif err := replaceNameservers(containerDNS, containerDNSResolv); err != nil {\n\treturn fmt.Errorf(\"replace nameservers: %w\", err)\n}\n// after\nif _, statErr := os.Stat(resolv); statErr != nil {\n\treturn fmt.Errorf(\"host %s unreadable: %w\", resolv, statErr)\n}\nif err := replaceNameservers(containerDNS, containerDNSResolv); err != nil {\n\treturn fmt.Errorf(\"replace nameservers: %w\", err)\n}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(\"/etc/resolv.conf\"); err != nil {\n\treturn fmt.Errorf(\"cannot set up DNS: /etc/resolv.conf unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check /etc/resolv.conf exists and is readable before namespace setup","Run netinst setup as root with CAP_SYS_ADMIN","Log the wrapped inner error to identify the exact failing file","Watch for disk-full (ENOSPC) when writing the container resolv.conf"],"tags":["network","dns","go","filesystem"],"backgroundTag":"resolv-conf-setup-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}