dagger/dagger · error

create container hosts tmp file: %w

Error message

create container hosts tmp file: %w

What it means

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.

Source

Thrown at engine/engineutil/executor_spec.go:290

	if len(state.execMD.HostAliases) == 0 {
		return nil
	}

	baseHostsFile, err := os.Open(state.hostsFilePath)
	if err != nil {
		return fmt.Errorf("open base hosts file: %w", err)
	}
	defer baseHostsFile.Close()

	baseHostsStat, err := baseHostsFile.Stat()
	if err != nil {
		return fmt.Errorf("stat base hosts file: %w", err)
	}

	ctrHostsFile, err := os.CreateTemp("", "hosts")
	if err != nil {
		return fmt.Errorf("create container hosts tmp file: %w", err)
	}
	defer ctrHostsFile.Close()
	state.hostsFilePath = ctrHostsFile.Name()
	state.cleanups.Add("remove hosts file", func() error {
		return os.RemoveAll(state.hostsFilePath)
	})

	if err := ctrHostsFile.Chmod(baseHostsStat.Mode().Perm()); err != nil {
		return fmt.Errorf("chmod hosts file: %w", err)
	}

	if _, err := io.Copy(ctrHostsFile, baseHostsFile); err != nil {
		return fmt.Errorf("copy base hosts file: %w", err)
	}

	for target, aliases := range state.execMD.HostAliases {
		var ips []net.IP
		var errs error

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Confirm the temp directory exists and is writable: `touch $TMPDIR/probe && rm $TMPDIR/probe`.
  2. Free disk space or relocate TMPDIR to a writable volume.
  3. Fix permissions on the temp dir for the engine's user.
  4. Inspect the wrapped cause with errors.Is/As (fs.ErrNotExist, fs.ErrPermission) to pinpoint the case.

Example fix

// before: read-only root filesystem, no writable /tmp
docker run --read-only myengine
// after: mount a writable tmpfs
 docker run --read-only --tmpfs /tmp:rw,size=64m myengine
Defensive patterns

Strategy: validation

Validate before calling

// precheck temp dir before engine start
probe := filepath.Join(os.TempDir(), ".hostsprobe")
if err := os.WriteFile(probe, nil, 0o600); err != nil {
	return fmt.Errorf("cannot create temp files in %s: %w", os.TempDir(), err)
}
os.Remove(probe)

Try / catch

if err != nil {
	if errors.Is(err, fs.ErrNotExist) {
		// create TMPDIR or unset it to fall back to /tmp
	} else if errors.Is(err, fs.ErrPermission) {
		// fix dir permissions or run with proper uid
	}
	return fmt.Errorf("hosts temp file: %w", err)
}

Prevention

When it happens

Trigger: os.CreateTemp("", "hosts") fails: TMPDIR//tmp missing, read-only, or full; process lacks write permission on the temp dir.

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

Related errors


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