From 58e10a7af2b2a84b3b7a4eaba0d92f5543f068b8 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Mon, 8 Feb 2021 17:20:36 +0100 Subject: [PATCH] Display warning in `docker compose down` if nothing to remove (no container, no network) For reference, `docker-compose` displays `WARNING: Network sentences_default not found` Signed-off-by: Guillaume Tardif --- local/compose/down.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/local/compose/down.go b/local/compose/down.go index e769653e3..0bd583ce9 100644 --- a/local/compose/down.go +++ b/local/compose/down.go @@ -34,6 +34,7 @@ import ( func (s *composeService) Down(ctx context.Context, projectName string, options compose.DownOptions) error { w := progress.ContextWriter(ctx) + resourceToRemove := false if options.Project == nil { project, err := s.projectFromContainerLabels(ctx, projectName) @@ -51,6 +52,9 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c if err != nil { return err } + if len(containers) > 0 { + resourceToRemove = true + } err = InReverseDependencyOrder(ctx, options.Project, func(c context.Context, service types.ServiceConfig) error { serviceContainers, others := containers.split(isService(service.Name)) @@ -80,12 +84,16 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c eg, _ := errgroup.WithContext(ctx) for _, n := range networks { + resourceToRemove = true networkID := n.ID networkName := n.Name eg.Go(func() error { return s.ensureNetworkDown(ctx, networkID, networkName) }) } + if !resourceToRemove { + w.Event(progress.NewEvent(projectName, progress.Done, "Warning: No resource found to remove")) + } return eg.Wait() }