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

Commit

Permalink
Fix wrong network aliases at container creation
Browse files Browse the repository at this point in the history
The aliases are not correctly set when starting the container.

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Jul 10, 2017
1 parent 0ad950c commit e4c5205
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 6 additions & 3 deletions docker/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,13 @@ func (s *Service) NetworkConnect(ctx context.Context, c *container.Container, ne
if err != nil {
return err
}
links := []string{}
var links []string
// TODO(vdemeester) handle link to self (?)
for k, v := range internalLinks {
links = append(links, strings.Join([]string{v, k}, ":"))
if len(internalLinks) > 0 {
links = []string{}
for k, v := range internalLinks {
links = append(links, strings.Join([]string{v, k}, ":"))
}
}
for _, v := range s.serviceConfig.ExternalLinks {
links = append(links, v)
Expand Down
19 changes: 18 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,25 @@ 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 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 e4c5205

Please sign in to comment.