mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Allow external volume drivers to host anonymous volumes and copy existing data from image.
Signed-off-by: Stephen Rust <srust@blockbridge.com>
This commit is contained in:
parent
05de2aadff
commit
7c70ad058f
4 changed files with 4 additions and 52 deletions
|
@ -105,7 +105,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig) (retC *containe
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig, img); err != nil {
|
if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,13 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
derr "github.com/docker/docker/errors"
|
derr "github.com/docker/docker/errors"
|
||||||
"github.com/docker/docker/image"
|
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/volume"
|
|
||||||
containertypes "github.com/docker/engine-api/types/container"
|
containertypes "github.com/docker/engine-api/types/container"
|
||||||
"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 (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig, img *image.Image) error {
|
func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
|
||||||
if err := daemon.Mount(container); err != nil {
|
if err := daemon.Mount(container); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -42,17 +40,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
|
||||||
return derr.ErrorCodeMountOverFile.WithArgs(path)
|
return derr.ErrorCodeMountOverFile.WithArgs(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeDriver := hostConfig.VolumeDriver
|
v, err := daemon.volumes.CreateWithRef(name, hostConfig.VolumeDriver, container.ID, nil)
|
||||||
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 := daemon.volumes.CreateWithRef(name, volumeDriver, container.ID, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/image"
|
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/volume"
|
"github.com/docker/docker/volume"
|
||||||
containertypes "github.com/docker/engine-api/types/container"
|
containertypes "github.com/docker/engine-api/types/container"
|
||||||
)
|
)
|
||||||
|
|
||||||
// createContainerPlatformSpecificSettings performs platform specific container create functionality
|
// createContainerPlatformSpecificSettings performs platform specific container create functionality
|
||||||
func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig, img *image.Image) error {
|
func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
|
||||||
for spec := range config.Volumes {
|
for spec := range config.Volumes {
|
||||||
|
|
||||||
mp, err := volume.ParseMountSpec(spec, hostConfig.VolumeDriver)
|
mp, err := volume.ParseMountSpec(spec, hostConfig.VolumeDriver)
|
||||||
|
@ -31,14 +30,6 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeDriver := hostConfig.VolumeDriver
|
volumeDriver := hostConfig.VolumeDriver
|
||||||
if mp.Destination != "" && img != nil {
|
|
||||||
if _, ok := img.ContainerConfig.Volumes[mp.Destination]; ok {
|
|
||||||
// check for whether bind is not specified and then set to local
|
|
||||||
if _, ok := container.MountPoints[mp.Destination]; !ok {
|
|
||||||
volumeDriver = volume.DefaultDriverName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the volume in the volume driver. If it doesn't exist,
|
// Create the volume in the volume driver. If it doesn't exist,
|
||||||
// a new one will be created.
|
// a new one will be created.
|
||||||
|
|
|
@ -296,33 +296,6 @@ 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) TestExternalVolumeDriverNamedCheckBindLocalVolume(c *check.C) {
|
|
||||||
err := s.d.StartWithBusybox()
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
|
|
||||||
expected := s.server.URL
|
|
||||||
dockerfile := fmt.Sprintf(`FROM busybox:latest
|
|
||||||
RUN mkdir /nobindthenlocalvol
|
|
||||||
RUN echo %s > /nobindthenlocalvol/test
|
|
||||||
VOLUME ["/nobindthenlocalvol"]`, expected)
|
|
||||||
|
|
||||||
img := "test-checkbindlocalvolume"
|
|
||||||
|
|
||||||
_, err = buildImageWithOutInDamon(s.d.sock(), img, dockerfile, true)
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
|
|
||||||
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")
|
|
||||||
c.Assert(err, checker.IsNil)
|
|
||||||
|
|
||||||
c.Assert(out, checker.Contains, expected)
|
|
||||||
|
|
||||||
c.Assert(s.ec.activations, checker.Equals, 1)
|
|
||||||
c.Assert(s.ec.creations, checker.Equals, 1)
|
|
||||||
c.Assert(s.ec.removals, checker.Equals, 1)
|
|
||||||
c.Assert(s.ec.mounts, checker.Equals, 1)
|
|
||||||
c.Assert(s.ec.unmounts, checker.Equals, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure a request to use a down driver doesn't block other requests
|
// Make sure a request to use a down driver doesn't block other requests
|
||||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *check.C) {
|
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *check.C) {
|
||||||
specPath := "/etc/docker/plugins/down-driver.spec"
|
specPath := "/etc/docker/plugins/down-driver.spec"
|
||||||
|
|
Loading…
Reference in a new issue