mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Merge pull request #19190 from srust/volume_driver_parity_again
Allow external volume drivers to host anonymous volumes again
This commit is contained in:
		
						commit
						455a505749
					
				
					 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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,15 +9,13 @@ import (
 | 
			
		|||
	"github.com/Sirupsen/logrus"
 | 
			
		||||
	"github.com/docker/docker/container"
 | 
			
		||||
	derr "github.com/docker/docker/errors"
 | 
			
		||||
	"github.com/docker/docker/image"
 | 
			
		||||
	"github.com/docker/docker/pkg/stringid"
 | 
			
		||||
	"github.com/docker/docker/volume"
 | 
			
		||||
	containertypes "github.com/docker/engine-api/types/container"
 | 
			
		||||
	"github.com/opencontainers/runc/libcontainer/label"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 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 {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -46,17 +44,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
 | 
			
		|||
			return derr.ErrorCodeMountOverFile.WithArgs(path)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		volumeDriver := hostConfig.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 := daemon.volumes.CreateWithRef(name, volumeDriver, container.ID, nil)
 | 
			
		||||
		v, err := daemon.volumes.CreateWithRef(name, hostConfig.VolumeDriver, container.ID, nil)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,14 +4,13 @@ import (
 | 
			
		|||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/docker/docker/container"
 | 
			
		||||
	"github.com/docker/docker/image"
 | 
			
		||||
	"github.com/docker/docker/pkg/stringid"
 | 
			
		||||
	"github.com/docker/docker/volume"
 | 
			
		||||
	containertypes "github.com/docker/engine-api/types/container"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 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 {
 | 
			
		||||
 | 
			
		||||
		mp, err := volume.ParseMountSpec(spec, hostConfig.VolumeDriver)
 | 
			
		||||
| 
						 | 
				
			
			@ -31,14 +30,6 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		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,
 | 
			
		||||
		// a new one will be created.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -296,33 +296,6 @@ func hostVolumePath(name string) string {
 | 
			
		|||
	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
 | 
			
		||||
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *check.C) {
 | 
			
		||||
	specPath := "/etc/docker/plugins/down-driver.spec"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue