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

Commit 1b708aa

Browse files
author
Vincent Demeester
authored
Merge pull request #483 from vdemeester/461-fix-network-alias
Fix wrong network aliases at container creation
2 parents 0ad950c + 5e593aa commit 1b708aa

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docker/service/service_create.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/Sirupsen/logrus"
1111
"github.com/docker/docker/api/types"
1212
containertypes "github.com/docker/docker/api/types/container"
13+
"github.com/docker/docker/api/types/network"
1314
"github.com/docker/libcompose/config"
1415
composecontainer "github.com/docker/libcompose/docker/container"
1516
"github.com/docker/libcompose/labels"
@@ -55,9 +56,28 @@ func (s *Service) createContainer(ctx context.Context, namer Namer, oldContainer
5556
configWrapper.HostConfig.Binds = util.Merge(configWrapper.HostConfig.Binds, volumeBinds(configWrapper.Config.Volumes, &info))
5657
}
5758

59+
networkConfig := configWrapper.NetworkingConfig
60+
if configWrapper.HostConfig.NetworkMode != "" && configWrapper.HostConfig.NetworkMode.IsUserDefined() {
61+
if networkConfig == nil {
62+
networkConfig = &network.NetworkingConfig{
63+
EndpointsConfig: map[string]*network.EndpointSettings{
64+
string(configWrapper.HostConfig.NetworkMode): {},
65+
},
66+
}
67+
}
68+
for key, value := range networkConfig.EndpointsConfig {
69+
70+
conf := value
71+
if value.Aliases == nil {
72+
value.Aliases = []string{}
73+
}
74+
value.Aliases = append(value.Aliases, s.name)
75+
networkConfig.EndpointsConfig[key] = conf
76+
}
77+
}
5878
logrus.Debugf("Creating container %s %#v", containerName, configWrapper)
5979
// FIXME(vdemeester): long-term will be container.Create(…)
60-
container, err := composecontainer.Create(ctx, client, containerName, configWrapper.Config, configWrapper.HostConfig, configWrapper.NetworkingConfig)
80+
container, err := composecontainer.Create(ctx, client, containerName, configWrapper.Config, configWrapper.HostConfig, networkConfig)
6181
if err != nil {
6282
return nil, err
6383
}

0 commit comments

Comments
 (0)