Skip to content

Commit

Permalink
Change networks opts into a slice when creating a container
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosnils committed Aug 25, 2017
1 parent a8567d8 commit e9f5de5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ type CreateContainerOpts struct {
Privileged bool
HostFQDN string
Labels map[string]string
Networks map[string]string
Networks []string
}

func (d *docker) CreateContainer(opts CreateContainerOpts) error {
Expand Down Expand Up @@ -286,17 +286,10 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) error {
Labels: opts.Labels,
}

networkConf := &network.NetworkingConfig{}
ec := map[string]*network.EndpointSettings{}
for netId, hostname := range opts.Networks {
es := &network.EndpointSettings{}
if hostname != "" {
es.Aliases = []string{hostname}
}
ec[netId] = es
networkConf := &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{opts.Networks[0]: &network.EndpointSettings{}},
}

networkConf.EndpointsConfig = ec
container, err := d.c.ContainerCreate(context.Background(), cf, h, networkConf, opts.ContainerName)

if err != nil {
Expand All @@ -314,6 +307,16 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) error {
}
}

//connect remaining networks if there are any
if len(opts.Networks) > 1 {
for _, nid := range opts.Networks {
err := d.c.NetworkConnect(context.Background(), nid, container.ID, &network.EndpointSettings{})
if err != nil {
return "", err
}
}
}

if err := d.copyIfSet(opts.ServerCert, "cert.pem", containerCertDir, opts.ContainerName); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion provisioner/dind.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (d *DinD) InstanceNew(session *types.Session, conf types.InstanceConfig) (*
CACert: conf.CACert,
HostFQDN: conf.Host,
Privileged: true,
Networks: map[string]string{session.Id: conf.Hostname},
Networks: []string{session.Id},
}

dockerClient, err := d.factory.GetForSession(session.Id)
Expand Down
2 changes: 1 addition & 1 deletion provisioner/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (d *windows) InstanceNew(session *types.Session, conf types.InstanceConfig)
CACert: conf.CACert,
Privileged: false,
HostFQDN: conf.Host,
Networks: map[string]string{session.Id: conf.Hostname},
Networks: []string{session.Id},
}

dockerClient, err := d.factory.GetForSession(session.Id)
Expand Down

0 comments on commit e9f5de5

Please sign in to comment.