dagger/dagger · error

replace nameservers

Error message

replace nameservers: %w

What it means

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.

Solutions

  1. 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
  2. Check write permissions and space for the container resolv.conf path returned by containerResolvPath(name)
  3. Run the setup with sufficient privileges (CAP_SYS_ADMIN / root) so the file and later mounts succeed
  4. Inspect the wrapped underlying error (%w) in the message — it names the exact failing file operation

Example fix

// before
if err := replaceNameservers(containerDNS, containerDNSResolv); err != nil {
	return fmt.Errorf("replace nameservers: %w", err)
}
// after
if _, statErr := os.Stat(resolv); statErr != nil {
	return fmt.Errorf("host %s unreadable: %w", resolv, statErr)
}
if err := replaceNameservers(containerDNS, containerDNSResolv); err != nil {
	return fmt.Errorf("replace nameservers: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat("/etc/resolv.conf"); err != nil {
	return fmt.Errorf("cannot set up DNS: /etc/resolv.conf unreadable: %w", err)
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/d4b4bdf31ff227cc. Report an issue: GitHub.

Appendix: source

Thrown at network/netinst/resolvconf.go:22

	"bufio"
	"fmt"
	"os"
	"strings"
	"syscall"
)

const resolv = "/etc/resolv.conf"

func InstallResolvconf(name, containerDNS string) error {
	containerDNSResolv := containerResolvPath(name)
	if err := createIfNeeded(containerDNSResolv); err != nil {
		return err
	}

	// create the resolv.conf for the container namespace by swapping out the
	// nameservers from the original, keeping any options and search domains
	if err := replaceNameservers(containerDNS, containerDNSResolv); err != nil {
		return fmt.Errorf("replace nameservers: %w", err)
	}

	if err := createIfNeeded(upstreamResolvPath); err != nil {
		return err
	}

	// preserve original resolv.conf at upstream path
	//
	// if resolv.conf is bind mounted, its source will be bind mounted here
	if err := syscall.Mount(resolv, upstreamResolvPath, "", syscall.MS_BIND, ""); err != nil {
		return fmt.Errorf("remount /etc/resolv.conf to upstream alias: %w", err)
	}

	// mount container resolv.conf over /etc/resolv.conf
	if err := syscall.Mount(containerDNSResolv, resolv, "", syscall.MS_BIND|syscall.MS_RDONLY, ""); err != nil {
		return fmt.Errorf("mount over /etc/resolv.conf: %w", err)
	}

View on GitHub (pinned to 82ba2681db)