From 7a6712afdb402c6b9e8621e66535e556a9419a55 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 8 Jan 2021 10:59:58 +0100 Subject: [PATCH] Do not inspect for double container name at creation time, this has already been checked, let moby error bubble up if there is a name clash at this stage Signed-off-by: Guillaume Tardif --- local/compose/convergence.go | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/local/compose/convergence.go b/local/compose/convergence.go index eb58e6204..0402cc5f8 100644 --- a/local/compose/convergence.go +++ b/local/compose/convergence.go @@ -26,7 +26,6 @@ import ( moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" - "github.com/docker/docker/client" "golang.org/x/sync/errgroup" status "github.com/docker/compose-cli/local/moby" @@ -42,11 +41,6 @@ const ( "Remove the custom name to scale the service.\n" ) -func containerExists(ctx context.Context, c *client.Client, name string) bool { - container, err := c.ContainerInspect(ctx, name) - return err == nil && container.ContainerJSONBase != nil && container.Name == "/"+name -} - func (s *composeService) ensureScale(ctx context.Context, actual []moby.Container, scale int, project *types.Project, service types.ServiceConfig) (*errgroup.Group, []moby.Container, error) { eg, _ := errgroup.WithContext(ctx) if len(actual) < scale { @@ -81,16 +75,7 @@ func (s *composeService) ensureScale(ctx context.Context, actual []moby.Containe } func (s *composeService) ensureService(ctx context.Context, observedState Containers, project *types.Project, service types.ServiceConfig) error { - actual, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{ - Filters: filters.NewArgs( - projectFilter(project.Name), - serviceFilter(service.Name), - ), - All: true, - }) - if err != nil { - return err - } + actual := observedState.filter(isService(service.Name)) scale, err := getScale(service) if err != nil { @@ -201,11 +186,6 @@ func getScale(config types.ServiceConfig) (int, error) { } func (s *composeService) createContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, name string, number int, autoRemove bool) error { - if containerExists(ctx, s.apiClient, name) { - return fmt.Errorf(doubledContainerNameWarning, - service.Name, - name) - } w := progress.ContextWriter(ctx) w.Event(progress.CreatingEvent(name)) err := s.createMobyContainer(ctx, project, service, name, number, nil, autoRemove)