hashicorp/nomad · critical

failed creating temporary directory for the AllocDir

Error message

failed creating temporary directory for the AllocDir: %v

What it means

When no custom alloc_dir is configured, the client creates a temporary directory with os.MkdirTemp("", "NomadClient") during init. If this OS call fails, startup aborts with this error. It means the system temp root itself is unusable.

Solutions

  1. Ensure TMPDIR (or /tmp) exists, is writable by the nomad user, and has free space: ls -ld "$TMPDIR" && df -h "$TMPDIR".
  2. Fix or unset a bad TMPDIR environment variable for the Nomad service (e.g. in the systemd unit).
  3. Configure an explicit alloc_dir so the temp directory path is never used.

Example fix

// before (systemd unit)
Environment=TMPDIR=/var/tmp/nomad  # directory missing
// after
ExecStartPre=/usr/bin/mkdir -p /var/tmp/nomad
Environment=TMPDIR=/var/tmp/nomad
# or set client { alloc_dir = "/var/lib/nomad/alloc" }
Defensive patterns

Strategy: validation

Validate before calling

tmp := os.TempDir()
if fi, err := os.Stat(tmp); err != nil || !fi.IsDir() {
    return fmt.Errorf("TMPDIR %q invalid: %v", tmp, err)
}
probe, err := os.MkdirTemp(tmp, "NomadClientProbe")
if err != nil {
    return fmt.Errorf("cannot create temp dir: %v", err)
}
os.Remove(probe)

Try / catch

if err := clientInit(); err != nil {
    if strings.Contains(err.Error(), "failed creating temporary directory for the AllocDir") {
        // fix TMPDIR or set explicit alloc_dir, then restart
    }
}

Prevention

When it happens

Trigger: client init without alloc_dir configured: os.MkdirTemp("", "NomadClient") returns error (typically because TMPDIR//tmp is missing, unwritable, or the disk is full).

Common situations: Containers with no /tmp, TMPDIR pointing to a non-existent path, full tmpfs (/tmp mounted with small size), or restrictive permissions on the temp root.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/55f37afb3ea295fb. Report an issue: GitHub.

Appendix: source

Thrown at client/client.go:749

	}

	// Ensure the alloc mounts dir exists if we are configured with a custom path.
	if conf.AllocMountsDir != "" {
		if err := os.MkdirAll(conf.AllocMountsDir, 0o711); err != nil {
			return fmt.Errorf("failed creating alloc mounts dir: %w", err)
		}
	}

	// Ensure the alloc dir exists if we are configured with a custom path.
	if conf.AllocDir != "" {
		if err := os.MkdirAll(conf.AllocDir, 0o711); err != nil {
			return fmt.Errorf("failed creating alloc dir: %w", err)
		}
	} else {
		// Otherwise make a temp directory to use.
		p, err := os.MkdirTemp("", "NomadClient")
		if err != nil {
			return fmt.Errorf("failed creating temporary directory for the AllocDir: %v", err)
		}

		p, err = filepath.EvalSymlinks(p)
		if err != nil {
			return fmt.Errorf("failed to find temporary directory for the AllocDir: %v", err)
		}

		// Change the permissions to have the execute bit
		if err := os.Chmod(p, 0o711); err != nil {
			return fmt.Errorf("failed to change directory permissions for the AllocDir: %v", err)
		}

		conf = c.UpdateConfig(func(c *config.Config) {
			c.AllocDir = p
			c.AllocMountsDir = p
		})
	}

View on GitHub (pinned to 482b49bf1a)