Add labels and additional network to connect container to
This commit is contained in:
@@ -217,6 +217,8 @@ type CreateContainerOpts struct {
|
|||||||
CACert []byte
|
CACert []byte
|
||||||
Privileged bool
|
Privileged bool
|
||||||
HostFQDN string
|
HostFQDN string
|
||||||
|
Labels map[string]string
|
||||||
|
AdditionalNetworks []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
|
func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
|
||||||
@@ -280,18 +282,14 @@ func (d *docker) CreateContainer(opts CreateContainerOpts) (string, error) {
|
|||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
Env: env,
|
Env: env,
|
||||||
//ExposedPorts: nat.PortSet{
|
Labels: opts.Labels,
|
||||||
//"2377": struct{}{},
|
|
||||||
//"4789/udp": struct{}{},
|
|
||||||
//"7946": struct{}{},
|
|
||||||
//"7946/udp": struct{}{},
|
|
||||||
//},
|
|
||||||
}
|
}
|
||||||
networkConf := &network.NetworkingConfig{
|
networkConf := &network.NetworkingConfig{
|
||||||
map[string]*network.EndpointSettings{
|
map[string]*network.EndpointSettings{
|
||||||
opts.SessionId: &network.EndpointSettings{Aliases: []string{opts.Hostname}},
|
opts.SessionId: &network.EndpointSettings{Aliases: []string{opts.Hostname}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@@ -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 {
|
if err := d.copyIfSet(opts.ServerCert, "cert.pem", containerCertDir, opts.ContainerName); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user