{"record":{"id":"ac449c90a03456de","repo":"juanfont/headscale","slug":"creating-container-w","errorCode":null,"errorMessage":"creating container: %w","messagePattern":"creating container: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/docker.go","lineNumber":88,"sourceCode":"\t\terr := cleanupBeforeTest(ctx)\n\t\tif err != nil && config.Verbose {\n\t\t\tlog.Printf(\"Warning: pre-test cleanup failed: %v\", err)\n\t\t}\n\t}\n\n\tgoTestCmd := buildGoTestCommand(config)\n\tif config.Verbose {\n\t\tlog.Printf(\"Command: %s\", strings.Join(goTestCmd, \" \"))\n\t}\n\n\timageName := \"golang:\" + config.GoVersion\n\tif err := ensureImageAvailable(ctx, cli, imageName, config.Verbose); err != nil { //nolint:noinlineerr\n\t\treturn fmt.Errorf(\"ensuring image availability: %w\", err)\n\t}\n\n\tresp, err := createGoTestContainer(ctx, cli, config, containerName, absLogsDir, goTestCmd)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating container: %w\", err)\n\t}\n\n\tif config.Verbose {\n\t\tlog.Printf(\"Created container: %s\", resp.ID)\n\t}\n\n\tif err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil { //nolint:noinlineerr\n\t\treturn fmt.Errorf(\"starting container: %w\", err)\n\t}\n\n\tlog.Printf(\"Starting test: %s\", config.TestPattern)\n\tlog.Printf(\"Run ID: %s\", runID)\n\tlog.Printf(\"Monitor with: docker logs -f %s\", containerName)\n\tlog.Printf(\"Logs directory: %s\", logsDir)\n\n\t// Start stats collection for container resource monitoring (if enabled)\n\tvar statsCollector *StatsCollector\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/docker.go#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the stale container: `docker rm -f hs-<runID>` (or `hi cleanup` / `go run ./cmd/hi doctor` per cmd/hi/README.md).","Confirm the logs directory exists and is writable by the Docker daemon.","Inspect the daemon error text embedded in the wrapped error — it names the exact config field rejected.","If using rootless Docker/colima, ensure the repo path is inside a shareable mount."],"exampleFix":"# before: stale container blocks creation\ndocker ps -a | grep hs-\n\n# after: clean stale runs then re-run\ngo run ./cmd/hi clean\ngo run ./cmd/hi run \"TestACL\"","handlingStrategy":"validation","validationCode":"// ensure no container with the generated name exists before running\nif _, err := cli.ContainerInspect(ctx, containerName); err == nil {\n    _ = cli.ContainerRemove(ctx, containerName, container.RemoveOptions{Force: true})\n} else if !client.IsErrNotFound(err) {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := runDockerTest(ctx, config); err != nil {\n    var nameTaken bool // daemon returns 409 Conflict for name collisions\n    if strings.Contains(err.Error(), \"creating container\") && strings.Contains(err.Error(), \"already in use\") {\n        nameTaken = true\n    }\n    if nameTaken {\n        // clean stale run and retry once\n    }\n}","preventionTips":["Run `go run ./cmd/hi clean` after crashed runs before starting a new one.","Never launch two hi runs with colliding names/ports concurrently.","Keep the logs directory present and writable."],"tags":["docker","container-create","hi-runner","integration-tests"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}