|
@@ -8,13 +8,15 @@ import (
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
|
|
|
+ "github.com/docker/docker/image"
|
|
|
"github.com/docker/docker/pkg/stringid"
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
+ "github.com/docker/docker/volume"
|
|
|
"github.com/opencontainers/runc/libcontainer/label"
|
|
|
)
|
|
|
|
|
|
// createContainerPlatformSpecificSettings performs platform specific container create functionality
|
|
|
-func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config) error {
|
|
|
+func createContainerPlatformSpecificSettings(container *Container, config *runconfig.Config, img *image.Image) error {
|
|
|
for spec := range config.Volumes {
|
|
|
var (
|
|
|
name, destination string
|
|
@@ -42,7 +44,17 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
|
|
|
return fmt.Errorf("cannot mount volume over existing file, file exists %s", path)
|
|
|
}
|
|
|
|
|
|
- v, err := createVolume(name, config.VolumeDriver)
|
|
|
+ volumeDriver := config.VolumeDriver
|
|
|
+ if destination != "" && img != nil {
|
|
|
+ if _, ok := img.ContainerConfig.Volumes[destination]; ok {
|
|
|
+ // check for whether bind is not specified and then set to local
|
|
|
+ if _, ok := container.MountPoints[destination]; !ok {
|
|
|
+ volumeDriver = volume.DefaultDriverName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ v, err := createVolume(name, volumeDriver)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -50,8 +62,11 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- if err := container.copyImagePathContent(v, destination); err != nil {
|
|
|
- return err
|
|
|
+ // never attempt to copy existing content in a container FS to a shared volume
|
|
|
+ if volumeDriver == volume.DefaultDriverName || volumeDriver == "" {
|
|
|
+ if err := container.copyImagePathContent(v, destination); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
container.addMountPointWithVolume(destination, v, true)
|