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

Commit

Permalink
Merge pull request #483 from vdemeester/461-fix-network-alias
Browse files Browse the repository at this point in the history
Fix wrong network aliases at container creation
  • Loading branch information
Vincent Demeester authored Jul 10, 2017
2 parents 0ad950c + 5e593aa commit 1b708aa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docker/service/service_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/libcompose/config"
composecontainer "github.com/docker/libcompose/docker/container"
"github.com/docker/libcompose/labels"
Expand Down Expand Up @@ -55,9 +56,28 @@ func (s *Service) createContainer(ctx context.Context, namer Namer, oldContainer
configWrapper.HostConfig.Binds = util.Merge(configWrapper.HostConfig.Binds, volumeBinds(configWrapper.Config.Volumes, &info))
}

networkConfig := configWrapper.NetworkingConfig
if configWrapper.HostConfig.NetworkMode != "" && configWrapper.HostConfig.NetworkMode.IsUserDefined() {
if networkConfig == nil {
networkConfig = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
string(configWrapper.HostConfig.NetworkMode): {},
},
}
}
for key, value := range networkConfig.EndpointsConfig {

conf := value
if value.Aliases == nil {
value.Aliases = []string{}
}
value.Aliases = append(value.Aliases, s.name)
networkConfig.EndpointsConfig[key] = conf
}
}
logrus.Debugf("Creating container %s %#v", containerName, configWrapper)
// FIXME(vdemeester): long-term will be container.Create(…)
container, err := composecontainer.Create(ctx, client, containerName, configWrapper.Config, configWrapper.HostConfig, configWrapper.NetworkingConfig)
container, err := composecontainer.Create(ctx, client, containerName, configWrapper.Config, configWrapper.HostConfig, networkConfig)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1b708aa

Please sign in to comment.