Skip to content

Commit

Permalink
Fix symlink mounting issues by evaluating symlinks directly on the LH…
Browse files Browse the repository at this point in the history
…S 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)
  • Loading branch information
tianon committed Jan 20, 2014
1 parent a60f0a0 commit 7379a22
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"net"
"os"
"path"
"path/filepath"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -645,7 +646,14 @@ func (container *Container) Start() (err error) {
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
}
}
Expand Down Expand Up @@ -806,7 +814,7 @@ func (container *Container) createVolumes() error {
if strings.ToLower(bindMap.Mode) == "rw" {
srcRW = true
}
if stat, err := os.Lstat(bindMap.SrcPath); err != nil {
if stat, err := os.Stat(bindMap.SrcPath); err != nil {
return err
} else {
volIsDir = stat.IsDir()
Expand All @@ -827,6 +835,13 @@ func (container *Container) createVolumes() error {
}
srcRW = true // RW by default
}

if p, err := filepath.EvalSymlinks(srcPath); err != nil {
return err
} else {
srcPath = p
}

container.Volumes[volPath] = srcPath
container.VolumesRW[volPath] = srcRW

Expand Down

0 comments on commit 7379a22

Please sign in to comment.