mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
mount: add BindOptions.NonRecursive (API v1.40)
This allows non-recursive bind-mount, i.e. mount(2) with "bind" rather than "rbind". Swarm-mode will be supported in a separate PR because of mutual vendoring. Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
mounttypes "github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/pkg/fileutils"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
@@ -58,6 +59,9 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
|
||||
Writable: m.RW,
|
||||
Propagation: string(m.Propagation),
|
||||
}
|
||||
if m.Spec.Type == mounttypes.TypeBind && m.Spec.BindOptions != nil {
|
||||
mnt.NonRecursive = m.Spec.BindOptions.NonRecursive
|
||||
}
|
||||
if m.Volume != nil {
|
||||
attributes := map[string]string{
|
||||
"driver": m.Volume.DriverName(),
|
||||
@@ -129,11 +133,15 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
|
||||
return err
|
||||
}
|
||||
|
||||
opts := "rbind,ro"
|
||||
if m.Writable {
|
||||
opts = "rbind,rw"
|
||||
bindMode := "rbind"
|
||||
if m.NonRecursive {
|
||||
bindMode = "bind"
|
||||
}
|
||||
|
||||
writeMode := "ro"
|
||||
if m.Writable {
|
||||
writeMode = "rw"
|
||||
}
|
||||
opts := strings.Join([]string{bindMode, writeMode}, ",")
|
||||
if err := mount.Mount(m.Source, dest, bindMountType, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user