From aedb9451a5e89140049c5ddc37f97531a1f0eca3 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Thu, 3 Nov 2016 15:57:38 -0400 Subject: [PATCH] Fix issue with cp to container volume dir In some cases, attempting to `docker cp` to a container's volume dir would fail due to the volume mounts not existing after performing a bind-mount on the container path prior to doing a pivot_root. This does not seem to be effecting all systems, but was found to be a problem on centos. The solution is to use an `rbind` rather than `bind` so that any existing mounts are carried over. The `MakePrivate` on `path` is no longer neccessary since we are already doing `MakeRPrivate` on `/`. Signed-off-by: Brian Goff Upstream-commit: e6eef7eb4911252c38c829775aa0d510a432476a Component: engine --- components/engine/pkg/chrootarchive/chroot_linux.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/engine/pkg/chrootarchive/chroot_linux.go b/components/engine/pkg/chrootarchive/chroot_linux.go index 3325329978..f9d7fed633 100644 --- a/components/engine/pkg/chrootarchive/chroot_linux.go +++ b/components/engine/pkg/chrootarchive/chroot_linux.go @@ -30,9 +30,11 @@ func chroot(path string) (err error) { if err := mount.MakeRPrivate("/"); err != nil { return err } - // ensure path is a mountpoint - if err := mount.MakePrivate(path); err != nil { - return err + + if mounted, _ := mount.Mounted(path); !mounted { + if err := mount.Mount(path, path, "bind", "rbind,rw"); err != nil { + return realChroot(path) + } } // setup oldRoot for pivot_root