Merge pull request #991 from gtardif/compose_network_error

Compose network error
This commit is contained in:
Nicolas De loof 2020-12-01 18:31:43 +01:00 committed by GitHub
commit 6bf76eebb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -176,7 +176,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
}
@ -675,6 +675,9 @@ 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,

View File

@ -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
}