From 1aba291cd4ad9d9d1172a72fb6371e67a1403e83 Mon Sep 17 00:00:00 2001 From: Joan Grau Date: Tue, 17 Sep 2024 12:49:02 +0200 Subject: [PATCH] Releases container layer on export 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 --- daemon/images/image_exporter.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/daemon/images/image_exporter.go b/daemon/images/image_exporter.go index d7b969e5038f9..bf523e473890d 100644 --- a/daemon/images/image_exporter.go +++ b/daemon/images/image_exporter.go @@ -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") } }() @@ -39,6 +38,8 @@ func (i *ImageService) PerformWithBaseFS(ctx context.Context, c *container.Conta return err } + defer rwlayer.Unmount() + return fn(basefs) }