Add labels and additional network to connect container to

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-08-25 10:21:59 -03:00
parent 52d523ac92
commit c44512f159

View File

@@ -217,6 +217,8 @@ type CreateContainerOpts struct {
CACert []byte
Privileged bool
HostFQDN string
Labels map[string]string
AdditionalNetworks []string
}
func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
@@ -280,18 +282,14 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
AttachStdout: true,
AttachStderr: true,
Env: env,
//ExposedPorts: nat.PortSet{
//"2377": struct{}{},
//"4789/udp": struct{}{},
//"7946": struct{}{},
//"7946/udp": struct{}{},
//},
Labels: opts.Labels,
}
networkConf := &network.NetworkingConfig{
map[string]*network.EndpointSettings{
opts.SessionId: &network.EndpointSettings{Aliases: []string{opts.Hostname}},
},
}
container, err := d.c.ContainerCreate(context.Background(), cf, h, networkConf, opts.ContainerName)
if err != nil {
@@ -309,6 +307,13 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
}
}
for _, netId := range opts.AdditionalNetworks {
set := &network.EndpointSettings{}
if err := d.c.NetworkConnect(context.Background(), netId, container.ID, set); err != nil {
return "", err
}
}
if err := d.copyIfSet(opts.ServerCert, "cert.pem", containerCertDir, opts.ContainerName); err != nil {
return "", err
}