mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15507 from clintonskitson/patch_issue_15467
added check for bind on create to determine local volume driver
This commit is contained in:
commit
19f7bfcda9
5 changed files with 88 additions and 6 deletions
|
@ -63,6 +63,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos
|
||||||
if err := daemon.mergeAndVerifyConfig(config, img); err != nil {
|
if err := daemon.mergeAndVerifyConfig(config, img); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if hostConfig == nil {
|
if hostConfig == nil {
|
||||||
hostConfig = &runconfig.HostConfig{}
|
hostConfig = &runconfig.HostConfig{}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +98,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos
|
||||||
}
|
}
|
||||||
defer container.Unmount()
|
defer container.Unmount()
|
||||||
|
|
||||||
if err := createContainerPlatformSpecificSettings(container, config); err != nil {
|
if err := createContainerPlatformSpecificSettings(container, config, img); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,15 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
|
"github.com/docker/docker/volume"
|
||||||
"github.com/opencontainers/runc/libcontainer/label"
|
"github.com/opencontainers/runc/libcontainer/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// createContainerPlatformSpecificSettings performs platform specific container create functionality
|
// 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 {
|
for spec := range config.Volumes {
|
||||||
var (
|
var (
|
||||||
name, destination string
|
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)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -50,8 +62,11 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := container.copyImagePathContent(v, destination); err != nil {
|
// never attempt to copy existing content in a container FS to a shared volume
|
||||||
return err
|
if volumeDriver == volume.DefaultDriverName || volumeDriver == "" {
|
||||||
|
if err := container.copyImagePathContent(v, destination); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
container.addMountPointWithVolume(destination, v, true)
|
container.addMountPointWithVolume(destination, v, true)
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
// createContainerPlatformSpecificSettings performs platform specific container create functionality
|
// 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 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,3 +244,38 @@ func (s DockerExternalVolumeSuite) TestStartExternalVolumeDriverDeleteContainer(
|
||||||
func hostVolumePath(name string) string {
|
func hostVolumePath(name string) string {
|
||||||
return fmt.Sprintf("/var/lib/docker/volumes/%s", name)
|
return fmt.Sprintf("/var/lib/docker/volumes/%s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerExternalVolumeSuite) TestStartExternalNamedVolumeDriverCheckBindLocalVolume(c *check.C) {
|
||||||
|
if err := s.d.StartWithBusybox(); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := s.server.URL
|
||||||
|
|
||||||
|
dockerfile := fmt.Sprintf(`FROM busybox:latest
|
||||||
|
RUN mkdir /nobindthenlocalvol
|
||||||
|
RUN echo %s > /nobindthenlocalvol/test
|
||||||
|
VOLUME ["/nobindthenlocalvol"]`, expected)
|
||||||
|
|
||||||
|
img := "test-checkbindlocalvolume"
|
||||||
|
|
||||||
|
args := []string{"--host", s.d.sock()}
|
||||||
|
buildOut, err := buildImageArgs(args, img, dockerfile, true)
|
||||||
|
fmt.Println(buildOut)
|
||||||
|
|
||||||
|
out, err := s.d.Cmd("run", "--rm", "--name", "test-data-nobind", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver", img, "cat", "/nobindthenlocalvol/test")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(out)
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(out, expected) {
|
||||||
|
c.Fatalf("External volume mount failed. Output: %s\n", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Assert(s.ec.activations, check.Equals, 1)
|
||||||
|
c.Assert(s.ec.creations, check.Equals, 1)
|
||||||
|
c.Assert(s.ec.removals, check.Equals, 1)
|
||||||
|
c.Assert(s.ec.mounts, check.Equals, 1)
|
||||||
|
c.Assert(s.ec.unmounts, check.Equals, 1)
|
||||||
|
}
|
||||||
|
|
|
@ -1353,3 +1353,33 @@ func createTmpFile(c *check.C, content string) string {
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildImageArgs(args []string, name, dockerfile string, useCache bool) (string, error) {
|
||||||
|
id, _, err := buildImageWithOutArgs(args, name, dockerfile, useCache)
|
||||||
|
return id, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildImageWithOutArgs(args []string, name, dockerfile string, useCache bool) (string, string, error) {
|
||||||
|
buildCmd := buildImageCmdArgs(args, name, dockerfile, useCache)
|
||||||
|
out, exitCode, err := runCommandWithOutput(buildCmd)
|
||||||
|
if err != nil || exitCode != 0 {
|
||||||
|
return "", out, fmt.Errorf("failed to build the image: %s", out)
|
||||||
|
}
|
||||||
|
id, err := getIDByName(name)
|
||||||
|
if err != nil {
|
||||||
|
return "", out, err
|
||||||
|
}
|
||||||
|
return id, out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildImageCmdArgs(args []string, name, dockerfile string, useCache bool) *exec.Cmd {
|
||||||
|
args = append(args, []string{"-D", "build", "-t", name}...)
|
||||||
|
if !useCache {
|
||||||
|
args = append(args, "--no-cache")
|
||||||
|
}
|
||||||
|
args = append(args, "-")
|
||||||
|
buildCmd := exec.Command(dockerBinary, args...)
|
||||||
|
buildCmd.Stdin = strings.NewReader(dockerfile)
|
||||||
|
return buildCmd
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue