Skip to content

Commit

Permalink
Merge pull request #6346 from hashicorp/b-docker-resilient-start
Browse files Browse the repository at this point in the history
docker: remove containers on creation failures
  • Loading branch information
Mahmood Ali committed Sep 18, 2019
2 parents 7512c42 + 8c29de2 commit 8602b12
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ CREATE:
container, err := d.createContainer(client, containerCfg, driverConfig.Image)
if err != nil {
d.logger.Error("failed to create container", "error", err)
client.RemoveContainer(docker.RemoveContainerOptions{
ID: containerCfg.Name,
Force: true,
})
return nil, nil, nstructs.WrapRecoverable(fmt.Sprintf("failed to create container: %v", err), err)
}

Expand Down Expand Up @@ -307,6 +311,10 @@ CREATE:
if err != nil {
msg := "failed to inspect started container"
d.logger.Error(msg, "error", err)
client.RemoveContainer(docker.RemoveContainerOptions{
ID: container.ID,
Force: true,
})
return nil, nil, nstructs.NewRecoverableError(fmt.Errorf("%s %s: %s", msg, container.ID, err), true)
}
container = runningContainer
Expand Down

0 comments on commit 8602b12

Please sign in to comment.