Skip to content

Commit

Permalink
Merge pull request #5768 from hashicorp/b-nmd-1489-cleanup-docker-images
Browse files Browse the repository at this point in the history
Cleanup docker images
  • Loading branch information
Chris Baker committed Jun 4, 2019
2 parents 9349f48 + 7b6d233 commit 168e3e9
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ BUG FIXES:
* client: Job validation now checks that the datacenter field does not contain empty strings [[GH-5665](https://github.com/hashicorp/nomad/pull/5665)]
* client: Fix network port mapping related environment variables when running with Nomad 0.8 servers [[GH-5587](https://github.com/hashicorp/nomad/issues/5587)]
* client: Fix issue with terminal state deployments being modified when allocation subsequently fails [[GH-5645](https://github.com/hashicorp/nomad/issues/5645)]
* driver/docker: Fix regression around image GC [[GH-5768](https://github.com/hashicorp/nomad/issues/5768)]
* metrics: Fixed stale metrics [[GH-5540](https://github.com/hashicorp/nomad/issues/5540)]
* vault: Fix renewal time to be 1/2 lease duration with jitter [[GH-5479](https://github.com/hashicorp/nomad/issues/5479)]

Expand Down
30 changes: 23 additions & 7 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,14 +1107,30 @@ func (d *Driver) DestroyTask(taskID string, force bool) error {

c, err := h.client.InspectContainer(h.containerID)
if err != nil {
return fmt.Errorf("failed to inspect container state: %v", err)
}
if c.State.Running && !force {
return fmt.Errorf("must call StopTask for the given task before Destroy or set force to true")
}
switch err.(type) {
case *docker.NoSuchContainer:
h.logger.Info("container was removed out of band, will proceed with DestroyTask",
"error", err)
default:
return fmt.Errorf("failed to inspect container state: %v", err)
}
} else {
if c.State.Running {
if !force {
return fmt.Errorf("must call StopTask for the given task before Destroy or set force to true")
}
if err := h.client.StopContainer(h.containerID, 0); err != nil {
h.logger.Warn("failed to stop container during destroy", "error", err)
}
}

if err := h.client.StopContainer(h.containerID, 0); err != nil {
h.logger.Warn("failed to stop container during destroy", "error", err)
if h.removeContainerOnExit {
if err := h.client.RemoveContainer(docker.RemoveContainerOptions{ID: h.containerID, RemoveVolumes: true, Force: true}); err != nil {
h.logger.Error("error removing container", "error", err)
}
} else {
h.logger.Debug("not removing container due to config")
}
}

if err := d.cleanupImage(h); err != nil {
Expand Down
Loading

0 comments on commit 168e3e9

Please sign in to comment.