From 2d9c0ee7d412bcc5017d3a5da470348c580ab20f Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 8 Dec 2022 18:53:47 +0100 Subject: [PATCH] Fix corner case when there's no container to attach to Signed-off-by: Nicolas De Loof --- pkg/compose/attach.go | 3 +++ pkg/compose/start.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pkg/compose/attach.go b/pkg/compose/attach.go index 52e90519351..729916446eb 100644 --- a/pkg/compose/attach.go +++ b/pkg/compose/attach.go @@ -37,6 +37,9 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis if err != nil { return nil, err } + if len(containers) == 0 { + return containers, nil + } containers.sorted() // This enforce predictable colors assignment diff --git a/pkg/compose/start.go b/pkg/compose/start.go index bd0093516f1..2506992cb57 100644 --- a/pkg/compose/start.go +++ b/pkg/compose/start.go @@ -112,6 +112,9 @@ type containerWatchFn func(container moby.Container) error // watchContainers uses engine events to capture container start/die and notify ContainerEventListener func (s *composeService) watchContainers(ctx context.Context, projectName string, services, required []string, listener api.ContainerEventListener, containers Containers, onStart containerWatchFn) error { + if len(containers) == 0 { + return nil + } if len(required) == 0 { required = services }