Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Fix: no connect & start if not recreated #504

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions docker/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func (s *Service) up(ctx context.Context, imageName string, create bool, options

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

newService := false
if len(containers) == 0 && create {
namer, err := s.namer(ctx, 1)
if err != nil {
Expand All @@ -323,27 +324,32 @@ func (s *Service) up(ctx context.Context, imageName string, create bool, options
return err
}
containers = []*container.Container{c}
newService = true
}

return s.eachContainer(ctx, containers, func(c *container.Container) error {
var err error
if create {

oldContainerID := c.ID()

if !newService {
c, err = s.recreateIfNeeded(ctx, c, options.NoRecreate, options.ForceRecreate)
if err != nil {
return err
}
}

if err := s.connectContainerToNetworks(ctx, c, false); err != nil {
return err
}

err = c.Start(ctx)
if newService || oldContainerID != c.ID() {
if err := s.connectContainerToNetworks(ctx, c, false); err != nil {
return err
}

if err == nil {
s.project.Notify(events.ContainerStarted, s.name, map[string]string{
"name": c.Name(),
})
err = c.Start(ctx)
if err == nil {
s.project.Notify(events.ContainerStarted, s.name, map[string]string{
"name": c.Name(),
})
}
}

return err
Expand Down