diff --git a/daemon/container.go b/daemon/container.go index 4f7864b5d1..528dcf8867 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -20,14 +20,12 @@ import ( "github.com/docker/docker/daemon/network" derr "github.com/docker/docker/errors" "github.com/docker/docker/pkg/broadcaster" - "github.com/docker/docker/pkg/fileutils" "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/nat" "github.com/docker/docker/pkg/promise" "github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/pkg/system" + "github.com/docker/docker/runconfig" "github.com/docker/docker/volume" ) @@ -514,77 +512,6 @@ func (container *Container) shouldRestart() bool { (container.hostConfig.RestartPolicy.Name == "on-failure" && container.ExitCode != 0) } -func (daemon *Daemon) mountVolumes(container *Container) error { - mounts, err := daemon.setupMounts(container) - if err != nil { - return err - } - - for _, m := range mounts { - dest, err := container.GetResourcePath(m.Destination) - if err != nil { - return err - } - - var stat os.FileInfo - stat, err = os.Stat(m.Source) - if err != nil { - return err - } - if err = fileutils.CreateIfNotExists(dest, stat.IsDir()); err != nil { - return err - } - - opts := "rbind,ro" - if m.Writable { - opts = "rbind,rw" - } - - if err := mount.Mount(m.Source, dest, "bind", opts); err != nil { - return err - } - } - - return nil -} - -func (container *Container) unmountVolumes(forceSyscall bool) error { - var ( - volumeMounts []volume.MountPoint - err error - ) - - for _, mntPoint := range container.MountPoints { - dest, err := container.GetResourcePath(mntPoint.Destination) - if err != nil { - return err - } - - volumeMounts = append(volumeMounts, volume.MountPoint{Destination: dest, Volume: mntPoint.Volume}) - } - - // Append any network mounts to the list (this is a no-op on Windows) - if volumeMounts, err = appendNetworkMounts(container, volumeMounts); err != nil { - return err - } - - for _, volumeMount := range volumeMounts { - if forceSyscall { - if err := system.Unmount(volumeMount.Destination); err != nil { - logrus.Warnf("%s unmountVolumes: Failed to force umount %v", container.ID, err) - } - } - - if volumeMount.Volume != nil { - if err := volumeMount.Volume.Unmount(); err != nil { - return err - } - } - } - - return nil -} - func (container *Container) addBindMountPoint(name, source, destination string, rw bool) { container.MountPoints[destination] = &volume.MountPoint{ Name: name, diff --git a/daemon/container_unix.go b/daemon/container_unix.go index 729fb1520f..ceaf4a03b1 100644 --- a/daemon/container_unix.go +++ b/daemon/container_unix.go @@ -20,7 +20,9 @@ import ( "github.com/docker/docker/daemon/network" derr "github.com/docker/docker/errors" "github.com/docker/docker/pkg/directory" + "github.com/docker/docker/pkg/fileutils" "github.com/docker/docker/pkg/idtools" + "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/nat" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/symlink" @@ -1435,3 +1437,74 @@ func (container *Container) ipcMounts() []execdriver.Mount { func detachMounted(path string) error { return syscall.Unmount(path, syscall.MNT_DETACH) } + +func (daemon *Daemon) mountVolumes(container *Container) error { + mounts, err := daemon.setupMounts(container) + if err != nil { + return err + } + + for _, m := range mounts { + dest, err := container.GetResourcePath(m.Destination) + if err != nil { + return err + } + + var stat os.FileInfo + stat, err = os.Stat(m.Source) + if err != nil { + return err + } + if err = fileutils.CreateIfNotExists(dest, stat.IsDir()); err != nil { + return err + } + + opts := "rbind,ro" + if m.Writable { + opts = "rbind,rw" + } + + if err := mount.Mount(m.Source, dest, "bind", opts); err != nil { + return err + } + } + + return nil +} + +func (container *Container) unmountVolumes(forceSyscall bool) error { + var ( + volumeMounts []volume.MountPoint + err error + ) + + for _, mntPoint := range container.MountPoints { + dest, err := container.GetResourcePath(mntPoint.Destination) + if err != nil { + return err + } + + volumeMounts = append(volumeMounts, volume.MountPoint{Destination: dest, Volume: mntPoint.Volume}) + } + + // Append any network mounts to the list (this is a no-op on Windows) + if volumeMounts, err = appendNetworkMounts(container, volumeMounts); err != nil { + return err + } + + for _, volumeMount := range volumeMounts { + if forceSyscall { + if err := system.Unmount(volumeMount.Destination); err != nil { + logrus.Warnf("%s unmountVolumes: Failed to force umount %v", container.ID, err) + } + } + + if volumeMount.Volume != nil { + if err := volumeMount.Volume.Unmount(); err != nil { + return err + } + } + } + + return nil +} diff --git a/daemon/container_windows.go b/daemon/container_windows.go index 5a73d2f6b4..86ab0f1f8f 100644 --- a/daemon/container_windows.go +++ b/daemon/container_windows.go @@ -190,3 +190,16 @@ func (container *Container) ipcMounts() []execdriver.Mount { func getDefaultRouteMtu() (int, error) { return -1, errSystemNotSupported } + +// TODO Windows: Fix Post-TP4. This is a hack to allow docker cp to work +// against containers which have volumes. You will still be able to cp +// to somewhere on the container drive, but not to any mounted volumes +// inside the container. Without this fix, docker cp is broken to any +// container which has a volume, regardless of where the file is inside the +// container. +func (daemon *Daemon) mountVolumes(container *Container) error { + return nil +} +func (container *Container) unmountVolumes(forceSyscall bool) error { + return nil +}