Skip to content

Commit

Permalink
Releases container layer on export
Browse files Browse the repository at this point in the history
When running docker export command the container layer
is only released in case there is an error.

This makes the daemon not being able to remove
them when using docker rmi or docker system prune
leaving the container layer and the image used
in an orphaned state on the docker file system.

After applying this patch, the layer is always
released allowing dockerd to remove/prune it.

Signed-off-by: Joan Grau <[email protected]>
  • Loading branch information
Joan Grau authored and grautxo committed Oct 19, 2024
1 parent 5098132 commit 1aba291
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions daemon/images/image_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Conta
if err != nil {
return err
}

defer func() {
err := i.ReleaseLayer(rwlayer)
if err != nil {
err2 := i.ReleaseLayer(rwlayer)
if err2 != nil {
log.G(ctx).WithError(err2).WithField("container", c.ID).Warn("Failed to release layer")
}
log.G(ctx).WithError(err).WithField("container", c.ID).Warn("Failed to release layer")
}
}()

Expand All @@ -39,6 +38,8 @@ func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Conta
return err
}

defer rwlayer.Unmount()

return fn(basefs)
}

Expand Down

0 comments on commit 1aba291

Please sign in to comment.