Add labels and additional network to connect container to
This commit is contained in:
@@ -206,17 +206,19 @@ func (d *docker) DeleteContainer(id string) error {
|
||||
}
|
||||
|
||||
type CreateContainerOpts struct {
|
||||
Image string
|
||||
WindowsEndpoint string
|
||||
SessionId string
|
||||
PwdIpAddress string
|
||||
ContainerName string
|
||||
Hostname string
|
||||
ServerCert []byte
|
||||
ServerKey []byte
|
||||
CACert []byte
|
||||
Privileged bool
|
||||
HostFQDN string
|
||||
Image string
|
||||
WindowsEndpoint string
|
||||
SessionId string
|
||||
PwdIpAddress string
|
||||
ContainerName string
|
||||
Hostname string
|
||||
ServerCert []byte
|
||||
ServerKey []byte
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user