From bb37b8b1d8ead9a017bf7c46c762ebd19fa0661e Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sat, 27 Jan 2024 15:37:31 +0100 Subject: [PATCH] Add additional check if all containers have been removed --- cmd/backup/script.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/backup/script.go b/cmd/backup/script.go index a61f1d5..50d3d70 100644 --- a/cmd/backup/script.go +++ b/cmd/backup/script.go @@ -478,6 +478,25 @@ func (s *script) stopContainersAndServices() (func() error, error) { } else { scaledDownServices = append(scaledDownServices, service) } + + // progress.ServiceProgress returns too early, so we need to manually check + // whether all containers belonging to the service have actually been removed + for { + containers, err := s.cli.ContainerList(context.Background(), types.ContainerListOptions{ + Filters: filters.NewArgs(filters.KeyValuePair{ + Key: "label", + Value: fmt.Sprintf("com.docker.swarm.service.id=%s", service.ID), + }), + }) + if err != nil { + scaleDownErrors = append(scaleDownErrors, err) + break + } + if len(containers) == 0 { + break + } + time.Sleep(time.Second) + } } }