|
|
@ -39,9 +39,9 @@ type Client interface {
|
|
|
|
// NewClient returns a new Client instance which can be used to interact with
|
|
|
|
// NewClient returns a new Client instance which can be used to interact with
|
|
|
|
// the Docker API.
|
|
|
|
// the Docker API.
|
|
|
|
// The client reads its configuration from the following environment variables:
|
|
|
|
// The client reads its configuration from the following environment variables:
|
|
|
|
// * DOCKER_HOST the docker-engine host to send api requests to
|
|
|
|
// - DOCKER_HOST the docker-engine host to send api requests to
|
|
|
|
// * DOCKER_TLS_VERIFY whether to verify tls certificates
|
|
|
|
// - DOCKER_TLS_VERIFY whether to verify tls certificates
|
|
|
|
// * DOCKER_API_VERSION the minimum docker api version to work with
|
|
|
|
// - DOCKER_API_VERSION the minimum docker api version to work with
|
|
|
|
func NewClient(opts ClientOptions) Client {
|
|
|
|
func NewClient(opts ClientOptions) Client {
|
|
|
|
cli, err := sdkClient.NewClientWithOpts(sdkClient.FromEnv)
|
|
|
|
cli, err := sdkClient.NewClientWithOpts(sdkClient.FromEnv)
|
|
|
|
|
|
|
|
|
|
|
@ -177,14 +177,20 @@ func (client dockerClient) StopContainer(c Container, timeout time.Duration) err
|
|
|
|
shortID := c.ID().ShortID()
|
|
|
|
shortID := c.ID().ShortID()
|
|
|
|
|
|
|
|
|
|
|
|
if c.IsRunning() {
|
|
|
|
if c.IsRunning() {
|
|
|
|
log.Infof("Stopping %s (%s) with %s", c.Name(), shortID, signal)
|
|
|
|
var maxWaitSeconds int = int(timeout.Milliseconds())
|
|
|
|
if err := client.api.ContainerKill(bg, idStr, signal); err != nil {
|
|
|
|
stopOptions := container.StopOptions{
|
|
|
|
|
|
|
|
Signal: "",
|
|
|
|
|
|
|
|
Timeout: &maxWaitSeconds,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("Stopping %s (%s) with %s, Timeout: %i", c.Name(), shortID, signal, maxWaitSeconds)
|
|
|
|
|
|
|
|
if err := client.api.ContainerStop(bg, idStr, stopOptions); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: This should probably be checked.
|
|
|
|
// TODO: This should probably be checked.
|
|
|
|
_ = client.waitForStopOrTimeout(c, timeout)
|
|
|
|
// ContainerStop has been implemented above with a SIGKILL if timeout is reached. This is no longer required
|
|
|
|
|
|
|
|
// _ = client.waitForStopOrTimeout(c, timeout)
|
|
|
|
|
|
|
|
|
|
|
|
if c.containerInfo.HostConfig.AutoRemove {
|
|
|
|
if c.containerInfo.HostConfig.AutoRemove {
|
|
|
|
log.Debugf("AutoRemove container %s, skipping ContainerRemove call.", shortID)
|
|
|
|
log.Debugf("AutoRemove container %s, skipping ContainerRemove call.", shortID)
|
|
|
|