Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: set force=true on remove image to handle images referenced by multiple tags #15962

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion drivers/docker/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (m *mockImageClient) InspectImage(id string) (*docker.Image, error) {
}, nil
}

func (m *mockImageClient) RemoveImage(id string) error {
func (m *mockImageClient) RemoveImageExtended(id string, options docker.RemoveImageOptions) error {
m.lock.Lock()
defer m.lock.Unlock()
m.removed[id]++
Expand Down