Change networks opts into a slice when creating a container
This commit is contained in:
@@ -219,7 +219,7 @@ type CreateContainerOpts struct {
|
|||||||
Privileged bool
|
Privileged bool
|
||||||
HostFQDN string
|
HostFQDN string
|
||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
Networks map[string]string
|
Networks []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *docker) CreateContainer(opts CreateContainerOpts) error {
|
func (d *docker) CreateContainer(opts CreateContainerOpts) error {
|
||||||
@@ -286,17 +286,10 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) error {
|
|||||||
Labels: opts.Labels,
|
Labels: opts.Labels,
|
||||||
}
|
}
|
||||||
|
|
||||||
networkConf := &network.NetworkingConfig{}
|
networkConf := &network.NetworkingConfig{
|
||||||
ec := map[string]*network.EndpointSettings{}
|
EndpointsConfig: map[string]*network.EndpointSettings{opts.Networks[0]: &network.EndpointSettings{}},
|
||||||
for netId, hostname := range opts.Networks {
|
|
||||||
es := &network.EndpointSettings{}
|
|
||||||
if hostname != "" {
|
|
||||||
es.Aliases = []string{hostname}
|
|
||||||
}
|
|
||||||
ec[netId] = es
|
|
||||||
}
|
}
|
||||||
|
|
||||||
networkConf.EndpointsConfig = ec
|
|
||||||
container, err := d.c.ContainerCreate(context.Background(), cf, h, networkConf, opts.ContainerName)
|
container, err := d.c.ContainerCreate(context.Background(), cf, h, networkConf, opts.ContainerName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -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 {
|
if err := d.copyIfSet(opts.ServerCert, "cert.pem", containerCertDir, opts.ContainerName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (d *DinD) InstanceNew(session *types.Session, conf types.InstanceConfig) (*
|
|||||||
CACert: conf.CACert,
|
CACert: conf.CACert,
|
||||||
HostFQDN: conf.Host,
|
HostFQDN: conf.Host,
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
Networks: map[string]string{session.Id: conf.Hostname},
|
Networks: []string{session.Id},
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerClient, err := d.factory.GetForSession(session.Id)
|
dockerClient, err := d.factory.GetForSession(session.Id)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func (d *windows) InstanceNew(session *types.Session, conf types.InstanceConfig)
|
|||||||
CACert: conf.CACert,
|
CACert: conf.CACert,
|
||||||
Privileged: false,
|
Privileged: false,
|
||||||
HostFQDN: conf.Host,
|
HostFQDN: conf.Host,
|
||||||
Networks: map[string]string{session.Id: conf.Hostname},
|
Networks: []string{session.Id},
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerClient, err := d.factory.GetForSession(session.Id)
|
dockerClient, err := d.factory.GetForSession(session.Id)
|
||||||
|
|||||||
Reference in New Issue
Block a user