From 752b5f6e508969dc6810ba22a0b260f8642756a4 Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Thu, 11 Jun 2015 15:16:28 -0400 Subject: [PATCH] Mount rootfs PRIVATE but volume mounts shared Currently we are remounting the entire OS as PRIVATE which breaks shared volume mounts. This patch only mounts the rootfs as PRIVATE which allows the volume mounts to be shared. Docker-DCO-1.1-Signed-off-by: Dan Walsh dwalsh@redhat.com (github: rhatdan) Docker-DCO-1.1-Signed-off-by: Dan Walsh (github: rhatdan) --- rootfs_linux.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rootfs_linux.go b/rootfs_linux.go index 0b0c3815c..c02db7a1e 100644 --- a/rootfs_linux.go +++ b/rootfs_linux.go @@ -168,6 +168,10 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error { if err := syscall.Mount("", dest, "none", uintptr(syscall.MS_PRIVATE), ""); err != nil { return err } + } else { + if err := syscall.Mount("", dest, "none", uintptr(syscall.MS_SLAVE), ""); err != nil { + return err + } } case "cgroup": mounts, err := cgroups.GetCgroupMounts() @@ -338,14 +342,15 @@ func mknodDevice(dest string, node *configs.Device) error { } func prepareRoot(config *configs.Config) error { + if err := syscall.Mount(config.Rootfs, config.Rootfs, "bind", syscall.MS_BIND|syscall.MS_REC, ""); err != nil { + return err + } + flag := syscall.MS_SLAVE | syscall.MS_REC if config.Privatefs { flag = syscall.MS_PRIVATE | syscall.MS_REC } - if err := syscall.Mount("", "/", "", uintptr(flag), ""); err != nil { - return err - } - return syscall.Mount(config.Rootfs, config.Rootfs, "bind", syscall.MS_BIND|syscall.MS_REC, "") + return syscall.Mount("", config.Rootfs, "", uintptr(flag), "") } func setReadonly() error {