juanfont/headscale · error

getting container logs: %w

Error message

getting container logs: %w

What it means

Returned by `streamAndWait` when `cli.ContainerLogs` fails to attach to the container's output streams before waiting. With Follow:true the attach is a long-lived connection, so this fails on daemon connection issues or if the container vanished between create/start and attach. The function returns exitCode -1, so the real exit status is unknown.

Source

Thrown at cmd/hi/docker.go:329

	hostConfig := &container.HostConfig{
		AutoRemove: false, // We'll remove manually for better control
		Binds:      binds,
		Mounts:     mounts,
	}

	return cli.ContainerCreate(ctx, containerConfig, hostConfig, nil, nil, containerName)
}

// streamAndWait streams container output and waits for completion.
func streamAndWait(ctx context.Context, cli *client.Client, containerID string) (int, error) {
	out, err := cli.ContainerLogs(ctx, containerID, container.LogsOptions{
		ShowStdout: true,
		ShowStderr: true,
		Follow:     true,
	})
	if err != nil {
		return -1, fmt.Errorf("getting container logs: %w", err)
	}
	defer out.Close()

	go func() {
		_, _ = io.Copy(os.Stdout, out)
	}()

	statusCh, errCh := cli.ContainerWait(ctx, containerID, container.WaitConditionNotRunning)
	select {
	case err := <-errCh:
		if err != nil {
			return -1, fmt.Errorf("waiting for container: %w", err)
		}
	case status := <-statusCh:
		return int(status.StatusCode), nil
	}

	return -1, ErrUnexpectedContainerWait

View on GitHub (pinned to 565fd254d0)

Solutions

  1. Verify the container still exists: `docker ps -a | grep hs-`.
  2. Check daemon stability (`docker info`, journalctl for dockerd).
  3. Ensure no parallel cleanup job removes containers during the run.
  4. Retrying the run from scratch is safe — this is a pre-streaming failure.
Defensive patterns

Strategy: retry

Validate before calling

// confirm the container is still present just before streaming
if _, err := cli.ContainerInspect(ctx, containerID); err != nil {
    return fmt.Errorf("container vanished before streaming: %w", err)
}

Try / catch

if err := runDockerTest(ctx, config); err != nil {
    if strings.Contains(err.Error(), "getting container logs") {
        // attach-stage failure: verify daemon and container, re-run from scratch
    }
}

Prevention

When it happens

Trigger: Daemon connection drops at attach time; the container was force-removed right after start; API version mismatch between client and daemon on the logs endpoint; context already cancelled/expired.

Common situations: Docker daemon restart or socket replacement mid-run; concurrent cleanup deleting the container; aggressive context timeouts wrapping `runDockerTest`.

Related errors


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