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 b134dd3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/docker/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (p *pullFuture) set(imageID string, err error) {
// Docker images
type DockerImageClient interface {
PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error
InspectImage(id string) (*docker.Image, error)
RemoveImage(id string) error
InspectImage(name string) (*docker.Image, error)
RemoveImageExtended(name 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 b134dd3

Please sign in to comment.