mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
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 <guillaume.tardif@gmail.com>
This commit is contained in:
parent
d24ffd97a0
commit
b1970f618c
@ -59,7 +59,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, detach
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for k, network := range project.Networks {
|
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)
|
network.Name = fmt.Sprintf("%s_%s", project.Name, k)
|
||||||
project.Networks[k] = network
|
project.Networks[k] = network
|
||||||
}
|
}
|
||||||
@ -559,9 +559,8 @@ func (s *composeService) ensureNetwork(ctx context.Context, n types.NetworkConfi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if errdefs.IsNotFound(err) {
|
if errdefs.IsNotFound(err) {
|
||||||
if n.External.External {
|
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{
|
createOpts := moby.NetworkCreate{
|
||||||
// TODO NameSpace Labels
|
// TODO NameSpace Labels
|
||||||
Labels: n.Labels,
|
Labels: n.Labels,
|
||||||
|
@ -240,9 +240,9 @@ func (s *composeService) runContainer(ctx context.Context, project *types.Projec
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
id := created.ID
|
id := created.ID
|
||||||
for net := range service.Networks {
|
for netName := range service.Networks {
|
||||||
name := fmt.Sprintf("%s_%s", project.Name, net)
|
network := project.Networks[netName]
|
||||||
err = s.connectContainerToNetwork(ctx, id, service.Name, name)
|
err = s.connectContainerToNetwork(ctx, id, service.Name, network.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user