{"record":{"id":"f4ef450ff12bbed4","repo":"juanfont/headscale","slug":"starting-container-w","errorCode":null,"errorMessage":"starting container: %w","messagePattern":"starting container: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/docker.go","lineNumber":96,"sourceCode":"\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\n\tif config.Stats {\n\t\tvar err error\n\n\t\tstatsCollector, err = NewStatsCollector(ctx)\n\t\tif err != nil {\n\t\t\tif config.Verbose {\n\t\t\t\tlog.Printf(\"Warning: failed to create stats collector: %v\", err)\n\t\t\t}","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/docker.go#L78-L114","documentation":"Returned when `cli.ContainerStart` fails for the freshly created test container. Creation succeeded but the daemon refused to start — most often due to port conflicts on published ports, invalid bind mounts, or runtime constraints. The container remains created (not running), so cleanup is still needed.","triggerScenarios":"Another `hi` run (or any process) already binds the headscale/Tailscale ports this container publishes; the bind-mounted logs dir disappeared between create and start; the daemon cannot apply the host config (memory limits without swap accounting: 'WARNING: Your kernel does not support swap limit capabilities').","commonSituations":"Two concurrent `hi run` invocations racing for the same ports; leftover tailscale/headscale containers from a previous run; Linux hosts missing cgroup swap accounting when memory limits are configured.","solutions":["Find and stop the port/container conflict: `docker ps` then `docker rm -f` the stale containers, or `go run ./cmd/hi clean`.","Avoid running two `hi run` commands concurrently against the same Docker daemon.","Read the wrapped daemon message — it names the conflicting port or mount.","Enable swap-accounting cgroup flags if memory limits are set (kernel cmdline `swapaccount=1`)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// free the ports the test will publish before starting\nfor _, port := range []string{\"8080/tcp\", \"3478/udp\"} { // adjust to actual published set\n    out, _ := exec.Command(\"sh\", \"-c\", fmt.Sprintf(\n        \"docker ps -q --filter publish=%s\", port)).Output()\n    if len(strings.TrimSpace(string(out))) > 0 {\n        return fmt.Errorf(\"port %s already bound by another container\", port)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runDockerTest(ctx, config); err != nil {\n    if strings.Contains(err.Error(), \"starting container\") {\n        // inspect `docker ps -a` for the created-but-not-started container,\n        // resolve the port/mount conflict named in the wrapped daemon error, then retry\n    }\n}","preventionTips":["Stop or remove containers bound to the test's ports before each run.","Serialize hi runs against a single daemon.","Read the daemon's own message inside the wrapped error — it names the conflicting resource."],"tags":["docker","container-start","port-conflict","hi-runner"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}