瀏覽代碼

Use real chroot if daemon is running in a user namespace

The namespace unshare+pivot root is not possible when running inside a
user namespace, so fallback to the original "real" chroot code.

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
Phil Estes 9 年之前
父節點
當前提交
dc950567c1
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      pkg/chrootarchive/chroot_linux.go

+ 5 - 0
pkg/chrootarchive/chroot_linux.go

@@ -8,6 +8,7 @@ import (
 	"syscall"
 
 	"github.com/docker/docker/pkg/mount"
+	rsystem "github.com/opencontainers/runc/libcontainer/system"
 )
 
 // chroot on linux uses pivot_root instead of chroot
@@ -17,6 +18,10 @@ import (
 // Old root is removed after the call to pivot_root so it is no longer available under the new root.
 // This is similar to how libcontainer sets up a container's rootfs
 func chroot(path string) (err error) {
+	// if the engine is running in a user namespace we need to use actual chroot
+	if rsystem.RunningInUserNS() {
+		return realChroot(path)
+	}
 	if err := syscall.Unshare(syscall.CLONE_NEWNS); err != nil {
 		return fmt.Errorf("Error creating mount namespace before pivot: %v", err)
 	}