run ContainerStart sequentially

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2025-05-20 08:16:26 +02:00 committed by Nicolas De loof
parent 2352a4a016
commit 4f6cc2a330
2 changed files with 16 additions and 1 deletions

View File

@ -650,9 +650,14 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
return created, err return created, err
} }
// force sequential calls to ContainerStart to prevent race condition in engine assigning ports from ranges
var startMx sync.Mutex
func (s *composeService) startContainer(ctx context.Context, ctr containerType.Summary) error { func (s *composeService) startContainer(ctx context.Context, ctr containerType.Summary) error {
w := progress.ContextWriter(ctx) w := progress.ContextWriter(ctx)
w.Event(progress.NewEvent(getContainerProgressName(ctr), progress.Working, "Restart")) w.Event(progress.NewEvent(getContainerProgressName(ctr), progress.Working, "Restart"))
startMx.Lock()
defer startMx.Unlock()
err := s.apiClient().ContainerStart(ctx, ctr.ID, containerType.StartOptions{}) err := s.apiClient().ContainerStart(ctx, ctr.ID, containerType.StartOptions{})
if err != nil { if err != nil {
return err return err

View File

@ -3,4 +3,14 @@ services:
image: nginx:alpine image: nginx:alpine
scale: 5 scale: 5
ports: ports:
- "6005-6015:80" - "6005-6015:80"
b:
image: nginx:alpine
ports:
- 80
c:
image: nginx:alpine
ports:
- 80