From 8953fda3efdc0b68da4a35bfef6d3d33354c0a14 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 15 Feb 2017 17:55:50 -0800 Subject: [PATCH] overlay2: fix unmounting layer without merge dir Signed-off-by: Tonis Tiigi (cherry picked from commit e1af6c8a5767e38957449a1d07e56104e317191b) Signed-off-by: Victor Vieux --- daemon/graphdriver/overlay2/overlay.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/daemon/graphdriver/overlay2/overlay.go b/daemon/graphdriver/overlay2/overlay.go index 07cd6ed5bc..4984d68dbd 100644 --- a/daemon/graphdriver/overlay2/overlay.go +++ b/daemon/graphdriver/overlay2/overlay.go @@ -30,7 +30,7 @@ import ( "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/go-units" + units "github.com/docker/go-units" "github.com/opencontainers/runc/libcontainer/label" ) @@ -553,7 +553,17 @@ func (d *Driver) Get(id string, mountLabel string) (s string, err error) { // Put unmounts the mount path created for the give id. func (d *Driver) Put(id string) error { - mountpoint := path.Join(d.dir(id), "merged") + dir := d.dir(id) + _, err := ioutil.ReadFile(path.Join(dir, lowerFile)) + if err != nil { + // If no lower, no mount happened and just return directly + if os.IsNotExist(err) { + return nil + } + return err + } + + mountpoint := path.Join(dir, "merged") if count := d.ctr.Decrement(mountpoint); count > 0 { return nil }