ContainerStart must run sequentially for engine to assing distinct ports within configured range

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2022-12-12 09:29:24 +01:00 committed by Nicolas De loof
parent 8f991a20db
commit 3ee2ab87bb
3 changed files with 23 additions and 11 deletions

View File

@ -721,21 +721,17 @@ func (s *composeService) startService(ctx context.Context, project *types.Projec
} }
w := progress.ContextWriter(ctx) w := progress.ContextWriter(ctx)
eg, ctx := errgroup.WithContext(ctx)
for _, container := range containers { for _, container := range containers {
if container.State == ContainerRunning { if container.State == ContainerRunning {
continue continue
} }
container := container
eg.Go(func() error {
eventName := getContainerProgressName(container) eventName := getContainerProgressName(container)
w.Event(progress.StartingEvent(eventName)) w.Event(progress.StartingEvent(eventName))
err := s.apiClient().ContainerStart(ctx, container.ID, moby.ContainerStartOptions{}) err := s.apiClient().ContainerStart(ctx, container.ID, moby.ContainerStartOptions{})
if err == nil { if err != nil {
return err
}
w.Event(progress.StartedEvent(eventName)) w.Event(progress.StartedEvent(eventName))
} }
return err return nil
})
}
return eg.Wait()
} }

View File

@ -56,3 +56,13 @@ func TestUpExitCodeFrom(t *testing.T) {
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans") c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans")
} }
func TestPortRange(t *testing.T) {
c := NewParallelCLI(t)
const projectName = "e2e-port-range"
res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/port-range/compose.yaml", "--project-name", projectName, "up", "-d")
res.Assert(t, icmd.Success)
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans")
}

View File

@ -0,0 +1,6 @@
services:
a:
image: nginx:alpine
scale: 5
ports:
- "6005-6015:80"