Skip to content

Commit

Permalink
docker: set force=true on remove image to handle images referenced by…
Browse files Browse the repository at this point in the history
… multiple tags

This PR changes our call of docker client RemoveImage() to RemoveImageExtended with
the Force=true option set. This fixes a bug where an image referenced by more than
one tag could never be garbage collected by Nomad. The Force option only applies to
stopped containers; it does not affect running workloads.
  • Loading branch information
shoenig committed Jan 30, 2023
1 parent f9d835f commit 1c15877
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/15962.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
docker: Fixed a bug where images referenced by multiple tags would not be GC'd
```
6 changes: 4 additions & 2 deletions drivers/docker/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *pullFuture) set(imageID string, err error) {
type DockerImageClient interface {
PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error
InspectImage(id string) (*docker.Image, error)
RemoveImage(id string) error
RemoveImageExtended(id string, opts docker.RemoveImageOptions) error
}

// LogEventFn is a callback which allows Drivers to emit task events.
Expand Down Expand Up @@ -320,7 +320,9 @@ func (d *dockerCoordinator) removeImageImpl(id string, ctx context.Context) {
d.imageLock.Unlock()

for i := 0; i < 3; i++ {
err := d.client.RemoveImage(id)
err := d.client.RemoveImageExtended(id, docker.RemoveImageOptions{
Force: true, // necessary to GC images referenced by multiple tags
})
if err == nil {
break
}
Expand Down

0 comments on commit 1c15877

Please sign in to comment.