From d24ffd97a05375d007358afda7cef47cc9fa79d3 Mon Sep 17 00:00:00 2001 From: Guillame Tardif Date: Mon, 30 Nov 2020 11:33:30 +0100 Subject: [PATCH 1/2] Local compose error when external network not available Signed-off-by: Guillame Tardif --- local/compose.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/local/compose.go b/local/compose.go index c550d5080..d8505c43f 100644 --- a/local/compose.go +++ b/local/compose.go @@ -558,6 +558,10 @@ func (s *composeService) ensureNetwork(ctx context.Context, n types.NetworkConfi _, err := s.apiClient.NetworkInspect(ctx, n.Name, moby.NetworkInspectOptions{}) if err != nil { if errdefs.IsNotFound(err) { + if n.External.External { + return fmt.Errorf("Network %s declared as external, but could not be found", n.Name) + } + createOpts := moby.NetworkCreate{ // TODO NameSpace Labels Labels: n.Labels, From b1970f618c4603220c3496ca26c6d18dd2d963d8 Mon Sep 17 00:00:00 2001 From: Guillame Tardif Date: Mon, 30 Nov 2020 14:50:03 +0100 Subject: [PATCH 2/2] Container networks: prefix network name only for internal networks or when name set (different from yaml key). No need to prefix again when connecting containers Signed-off-by: Guillame Tardif --- local/compose.go | 5 ++--- local/convergence.go | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/local/compose.go b/local/compose.go index d8505c43f..2df322b64 100644 --- a/local/compose.go +++ b/local/compose.go @@ -59,7 +59,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, detach return err } for k, network := range project.Networks { - if !network.External.External && network.Name != "" { + if !network.External.External && network.Name == k { network.Name = fmt.Sprintf("%s_%s", project.Name, k) project.Networks[k] = network } @@ -559,9 +559,8 @@ func (s *composeService) ensureNetwork(ctx context.Context, n types.NetworkConfi if err != nil { if errdefs.IsNotFound(err) { if n.External.External { - return fmt.Errorf("Network %s declared as external, but could not be found", n.Name) + return fmt.Errorf("network %s declared as external, but could not be found", n.Name) } - createOpts := moby.NetworkCreate{ // TODO NameSpace Labels Labels: n.Labels, diff --git a/local/convergence.go b/local/convergence.go index 9e3532219..94c768df7 100644 --- a/local/convergence.go +++ b/local/convergence.go @@ -240,9 +240,9 @@ func (s *composeService) runContainer(ctx context.Context, project *types.Projec return err } id := created.ID - for net := range service.Networks { - name := fmt.Sprintf("%s_%s", project.Name, net) - err = s.connectContainerToNetwork(ctx, id, service.Name, name) + for netName := range service.Networks { + network := project.Networks[netName] + err = s.connectContainerToNetwork(ctx, id, service.Name, network.Name) if err != nil { return err }