Fix symlink mounting issues by evaluating symlinks directly on the LHS of a bind-mount -v and by FollowSymlinkInScope on the RHS just before mounting

Tested successfully with variations around mounting /var/run and /var/run/docker.sock inside a "debian" container directly at /var/run/docker.sock where /var/run is a symlink to "/run" on both the host and in the container.

Fixes #3262

Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)
This commit is contained in:
Tianon Gravi 2014-01-11 03:31:01 -07:00
parent a60f0a0754
commit 7379a22a8d
1 changed files with 17 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import (
"net" "net"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
@ -645,7 +646,14 @@ func (container *Container) Start() (err error) {
mountAs = "rw" mountAs = "rw"
} }
if err := mount.Mount(v, path.Join(root, r), "none", fmt.Sprintf("bind,%s", mountAs)); err != nil { r = path.Join(root, r)
if p, err := utils.FollowSymlinkInScope(r, root); err != nil {
return err
} else {
r = p
}
if err := mount.Mount(v, r, "none", fmt.Sprintf("bind,%s", mountAs)); err != nil {
return err return err
} }
} }
@ -806,7 +814,7 @@ func (container *Container) createVolumes() error {
if strings.ToLower(bindMap.Mode) == "rw" { if strings.ToLower(bindMap.Mode) == "rw" {
srcRW = true srcRW = true
} }
if stat, err := os.Lstat(bindMap.SrcPath); err != nil { if stat, err := os.Stat(bindMap.SrcPath); err != nil {
return err return err
} else { } else {
volIsDir = stat.IsDir() volIsDir = stat.IsDir()
@ -827,6 +835,13 @@ func (container *Container) createVolumes() error {
} }
srcRW = true // RW by default srcRW = true // RW by default
} }
if p, err := filepath.EvalSymlinks(srcPath); err != nil {
return err
} else {
srcPath = p
}
container.Volumes[volPath] = srcPath container.Volumes[volPath] = srcPath
container.VolumesRW[volPath] = srcRW container.VolumesRW[volPath] = srcRW