juanfont/headscale · error

creating container: %w

Error message

creating container: %w

What it means

Returned when `cli.ContainerCreate` (via `createGoTestContainer`) fails while creating the container that will run `go test`. The wrapping message 'creating container' distinguishes creation failures from start/wait failures later in the same flow. Typical causes are bad mounts, name collisions, invalid env/host config, or daemon policy errors.

Source

Thrown at cmd/hi/docker.go:88

		err := cleanupBeforeTest(ctx)
		if err != nil && config.Verbose {
			log.Printf("Warning: pre-test cleanup failed: %v", err)
		}
	}

	goTestCmd := buildGoTestCommand(config)
	if config.Verbose {
		log.Printf("Command: %s", strings.Join(goTestCmd, " "))
	}

	imageName := "golang:" + config.GoVersion
	if err := ensureImageAvailable(ctx, cli, imageName, config.Verbose); err != nil { //nolint:noinlineerr
		return fmt.Errorf("ensuring image availability: %w", err)
	}

	resp, err := createGoTestContainer(ctx, cli, config, containerName, absLogsDir, goTestCmd)
	if err != nil {
		return fmt.Errorf("creating container: %w", err)
	}

	if config.Verbose {
		log.Printf("Created container: %s", resp.ID)
	}

	if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil { //nolint:noinlineerr
		return fmt.Errorf("starting container: %w", err)
	}

	log.Printf("Starting test: %s", config.TestPattern)
	log.Printf("Run ID: %s", runID)
	log.Printf("Monitor with: docker logs -f %s", containerName)
	log.Printf("Logs directory: %s", logsDir)

	// Start stats collection for container resource monitoring (if enabled)
	var statsCollector *StatsCollector

View on GitHub (pinned to 565fd254d0)

Solutions

  1. Remove the stale container: `docker rm -f hs-<runID>` (or `hi cleanup` / `go run ./cmd/hi doctor` per cmd/hi/README.md).
  2. Confirm the logs directory exists and is writable by the Docker daemon.
  3. Inspect the daemon error text embedded in the wrapped error — it names the exact config field rejected.
  4. If using rootless Docker/colima, ensure the repo path is inside a shareable mount.

Example fix

# before: stale container blocks creation
docker ps -a | grep hs-

# after: clean stale runs then re-run
go run ./cmd/hi clean
go run ./cmd/hi run "TestACL"
Defensive patterns

Strategy: validation

Validate before calling

// ensure no container with the generated name exists before running
if _, err := cli.ContainerInspect(ctx, containerName); err == nil {
    _ = cli.ContainerRemove(ctx, containerName, container.RemoveOptions{Force: true})
} else if !client.IsErrNotFound(err) {
    return err
}

Try / catch

if err := runDockerTest(ctx, config); err != nil {
    var nameTaken bool // daemon returns 409 Conflict for name collisions
    if strings.Contains(err.Error(), "creating container") && strings.Contains(err.Error(), "already in use") {
        nameTaken = true
    }
    if nameTaken {
        // clean stale run and retry once
    }
}

Prevention

When it happens

Trigger: A container with the same generated `containerName` already exists (stale run not cleaned up); the logs directory path cannot be bind-mounted; the Docker daemon rejects the host config (e.g. memory settings on a daemon without swap accounting); `os.Getwd` or project-root detection yields a path invalid for the mount spec.

Common situations: Re-running `hi run` after a previous crashed run left the old container behind; logs dir on a filesystem Docker can't mount; rootless Docker/colima rejecting a bind mount outside an allowed path; CI runners with restricted mount paths.

Related errors


AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15). Data as JSON: /api/errors/ac449c90a03456de. Report an issue: GitHub.