From c44512f159490994544f74e3e9d4c847605ce528 Mon Sep 17 00:00:00 2001 From: "Jonathan Leibiusky @xetorthio" Date: Fri, 25 Aug 2017 10:21:59 -0300 Subject: [PATCH] Add labels and additional network to connect container to --- docker/docker.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/docker/docker.go b/docker/docker.go index 01bfaf4..1c25597 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -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 }