Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit ceab35f

Browse files
committed
Fix: no connect & start if not recreated
Signed-off-by: xi.han <[email protected]>
1 parent 57bd716 commit ceab35f

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

docker/service/service.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ func (s *Service) up(ctx context.Context, imageName string, create bool, options
313313

314314
logrus.Debugf("Found %d existing containers for service %s", len(containers), s.name)
315315

316+
newService := false
316317
if len(containers) == 0 && create {
317318
namer, err := s.namer(ctx, 1)
318319
if err != nil {
@@ -323,27 +324,32 @@ func (s *Service) up(ctx context.Context, imageName string, create bool, options
323324
return err
324325
}
325326
containers = []*container.Container{c}
327+
newService = true
326328
}
327329

328330
return s.eachContainer(ctx, containers, func(c *container.Container) error {
329331
var err error
330-
if create {
332+
333+
oldContainerID := c.ID()
334+
335+
if !newService {
331336
c, err = s.recreateIfNeeded(ctx, c, options.NoRecreate, options.ForceRecreate)
332337
if err != nil {
333338
return err
334339
}
335340
}
336341

337-
if err := s.connectContainerToNetworks(ctx, c, false); err != nil {
338-
return err
339-
}
340-
341-
err = c.Start(ctx)
342+
if newService || oldContainerID != c.ID() {
343+
if err := s.connectContainerToNetworks(ctx, c, false); err != nil {
344+
return err
345+
}
342346

343-
if err == nil {
344-
s.project.Notify(events.ContainerStarted, s.name, map[string]string{
345-
"name": c.Name(),
346-
})
347+
err = c.Start(ctx)
348+
if err == nil {
349+
s.project.Notify(events.ContainerStarted, s.name, map[string]string{
350+
"name": c.Name(),
351+
})
352+
}
347353
}
348354

349355
return err

0 commit comments

Comments
 (0)