amir20/dozzle · error

failed to get host for container

Error message

failed to get host for container %s: %w

What it means

After FindContainerWithHost successfully resolves the container via the owning client, it calls client.Host(ctx) to fetch the Docker host information. This error wraps any failure from that call, so the container was found but its host metadata could not be retrieved, and nothing is stored in the TTL cache.

Solutions

  1. Check the wrapped error (%w cause) to identify the underlying transport failure.
  2. Verify the Docker host is reachable (docker info on that host, agent connectivity for remote hosts).
  3. Retry the lookup after connectivity is restored; the TTL cache means a successful later call will repopulate it.
Defensive patterns

Strategy: retry

Validate before calling

// Check host connectivity before resolving
if err := client.Ping(ctx); err != nil {
    return fmt.Errorf("docker host unreachable: %w", err)
}

Try / catch

c, host, err := listener.FindContainerWithHost(ctx, id, labels)
if err != nil {
    if errors.Is(err, context.DeadlineExceeded) || isTransportErr(err) {
        time.AfterFunc(backoff, func() { resolveAgain(id) })
        return
    }
    return err
}

Prevention

When it happens

Trigger: The owning client's Host() call fails: the Docker endpoint is unreachable, the socket/agent connection dropped, or the underlying Docker/agent API returned an error for the host query. Raised only when the container lookup itself already succeeded.

Common situations: Docker daemon restart or temporary socket unavailability, a remote agent host being offline, or multi-host setups where one node's connection is degraded while log events keep arriving from others.

Related errors


AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07). Data as JSON: /api/errors/39f84109a520b35c. Report an issue: GitHub.

Appendix: source

Thrown at internal/notification/log_listener.go:209

// FindContainerWithHost finds a container and its host by container ID, using a TTL cache.
func (l *ContainerLogListener) FindContainerWithHost(ctx context.Context, id string, labels container.ContainerLabels) (container.Container, container.Host, error) {
	if cached, ok := l.cache.Load(id); ok {
		return cached.container, cached.host, nil
	}

	client, exists := l.containerClients.Load(id)
	if !exists {
		return container.Container{}, container.Host{}, fmt.Errorf("container %s not found in any client", id)
	}

	c, err := client.FindContainer(ctx, id, labels)
	if err != nil {
		return container.Container{}, container.Host{}, err
	}

	host, err := client.Host(ctx)
	if err != nil {
		return container.Container{}, container.Host{}, fmt.Errorf("failed to get host for container %s: %w", id, err)
	}

	l.cache.Store(id, containerInfo{
		container: c,
		host:      host,
	})

	return c, host, nil
}

// LogChannel returns the channel for log events
func (l *ContainerLogListener) LogChannel() <-chan *container.LogEvent {
	return l.logChannel
}

// ListContainers returns all containers from all clients
func (l *ContainerLogListener) ListContainers() []container.Container {
	var result []container.Container

View on GitHub (pinned to d9463cbe21)