{"record":{"id":"39f84109a520b35c","repo":"amir20/dozzle","slug":"failed-to-get-host-for-container-s-w","errorCode":null,"errorMessage":"failed to get host for container %s: %w","messagePattern":"failed to get host for container (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/notification/log_listener.go","lineNumber":209,"sourceCode":"// FindContainerWithHost finds a container and its host by container ID, using a TTL cache.\nfunc (l *ContainerLogListener) FindContainerWithHost(ctx context.Context, id string, labels container.ContainerLabels) (container.Container, container.Host, error) {\n\tif cached, ok := l.cache.Load(id); ok {\n\t\treturn cached.container, cached.host, nil\n\t}\n\n\tclient, exists := l.containerClients.Load(id)\n\tif !exists {\n\t\treturn container.Container{}, container.Host{}, fmt.Errorf(\"container %s not found in any client\", id)\n\t}\n\n\tc, err := client.FindContainer(ctx, id, labels)\n\tif err != nil {\n\t\treturn container.Container{}, container.Host{}, err\n\t}\n\n\thost, err := client.Host(ctx)\n\tif err != nil {\n\t\treturn container.Container{}, container.Host{}, fmt.Errorf(\"failed to get host for container %s: %w\", id, err)\n\t}\n\n\tl.cache.Store(id, containerInfo{\n\t\tcontainer: c,\n\t\thost:      host,\n\t})\n\n\treturn c, host, nil\n}\n\n// LogChannel returns the channel for log events\nfunc (l *ContainerLogListener) LogChannel() <-chan *container.LogEvent {\n\treturn l.logChannel\n}\n\n// ListContainers returns all containers from all clients\nfunc (l *ContainerLogListener) ListContainers() []container.Container {\n\tvar result []container.Container","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/notification/log_listener.go#L191-L227","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the wrapped error (%w cause) to identify the underlying transport failure.","Verify the Docker host is reachable (docker info on that host, agent connectivity for remote hosts).","Retry the lookup after connectivity is restored; the TTL cache means a successful later call will repopulate it."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Check host connectivity before resolving\nif err := client.Ping(ctx); err != nil {\n    return fmt.Errorf(\"docker host unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"c, host, err := listener.FindContainerWithHost(ctx, id, labels)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || isTransportErr(err) {\n        time.AfterFunc(backoff, func() { resolveAgain(id) })\n        return\n    }\n    return err\n}","preventionTips":["Monitor Docker socket/agent connectivity.","Add retries with backoff around host resolution.","Watch for multi-host setups where one node is degraded."],"tags":["network","docker","host-resolution"],"backgroundTag":"upstream-api-error","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}