|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/network"
|
|
|
|
dockerclient "github.com/docker/docker/client"
|
|
|
|
dockerclient "github.com/docker/docker/client"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -118,17 +119,49 @@ func (client dockerClient) StartContainer(c Container) error {
|
|
|
|
bg := context.Background()
|
|
|
|
bg := context.Background()
|
|
|
|
config := c.runtimeConfig()
|
|
|
|
config := c.runtimeConfig()
|
|
|
|
hostConfig := c.hostConfig()
|
|
|
|
hostConfig := c.hostConfig()
|
|
|
|
|
|
|
|
networkConfig := &network.NetworkingConfig{EndpointsConfig: c.containerInfo.NetworkSettings.Networks}
|
|
|
|
|
|
|
|
// simpleNetworkConfig is a networkConfig with only 1 network.
|
|
|
|
|
|
|
|
// see: https://github.com/docker/docker/issues/29265
|
|
|
|
|
|
|
|
simpleNetworkConfig := func() *network.NetworkingConfig {
|
|
|
|
|
|
|
|
oneEndpoint := make(map[string]*network.EndpointSettings)
|
|
|
|
|
|
|
|
for k, v := range networkConfig.EndpointsConfig {
|
|
|
|
|
|
|
|
oneEndpoint[k] = v
|
|
|
|
|
|
|
|
// we only need 1
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return &network.NetworkingConfig{EndpointsConfig: oneEndpoint}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
name := c.Name()
|
|
|
|
name := c.Name()
|
|
|
|
|
|
|
|
|
|
|
|
log.Infof("Starting %s", name)
|
|
|
|
log.Infof("Starting %s", name)
|
|
|
|
creation, err := client.api.ContainerCreate(bg, config, hostConfig, nil, name)
|
|
|
|
creation, err := client.api.ContainerCreate(bg, config, hostConfig, simpleNetworkConfig, name)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.Debugf("Starting container %s (%s)", name, creation.ID)
|
|
|
|
log.Debugf("Starting container %s (%s)", name, creation.ID)
|
|
|
|
|
|
|
|
|
|
|
|
return client.api.ContainerStart(bg, creation.ID, types.ContainerStartOptions{})
|
|
|
|
err = client.api.ContainerStart(bg, creation.ID, types.ContainerStartOptions{})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for k := range simpleNetworkConfig.EndpointsConfig {
|
|
|
|
|
|
|
|
err = client.api.NetworkDisconnect(bg, k, creation.ID, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for k, v := range networkConfig.EndpointsConfig {
|
|
|
|
|
|
|
|
err = client.api.NetworkConnect(bg, k, creation.ID, v)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (client dockerClient) RenameContainer(c Container, newName string) error {
|
|
|
|
func (client dockerClient) RenameContainer(c Container, newName string) error {
|
|
|
|