Просмотр исходного кода

daemon: allow tmpfs to trump over VOLUME(s)

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
(cherry picked from commit 756f6cef4a1379e59d6511ee000e435d23659153)
Antonio Murdaca 9 лет назад
Родитель
Сommit
034d555d30

+ 2 - 1
container/container_windows.go

@@ -54,7 +54,8 @@ func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog fun
 
 
 // TmpfsMounts returns the list of tmpfs mounts
 // TmpfsMounts returns the list of tmpfs mounts
 func (container *Container) TmpfsMounts() []Mount {
 func (container *Container) TmpfsMounts() []Mount {
-	return nil
+	var mounts []Mount
+	return mounts
 }
 }
 
 
 // UpdateContainer updates configuration of a container
 // UpdateContainer updates configuration of a container

+ 3 - 2
daemon/oci_linux.go

@@ -480,9 +480,10 @@ func setMounts(daemon *Daemon, s *specs.Spec, c *container.Container, mounts []c
 		}
 		}
 
 
 		if m.Source == "tmpfs" {
 		if m.Source == "tmpfs" {
+			data := c.HostConfig.Tmpfs[m.Destination]
 			options := []string{"noexec", "nosuid", "nodev", volume.DefaultPropagationMode}
 			options := []string{"noexec", "nosuid", "nodev", volume.DefaultPropagationMode}
-			if m.Data != "" {
-				options = append(options, strings.Split(m.Data, ",")...)
+			if data != "" {
+				options = append(options, strings.Split(data, ",")...)
 			}
 			}
 
 
 			merged, err := mount.MergeTmpfsOptions(options)
 			merged, err := mount.MergeTmpfsOptions(options)

+ 2 - 1
daemon/volumes.go

@@ -129,7 +129,8 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
 			return err
 			return err
 		}
 		}
 
 
-		if binds[bind.Destination] {
+		_, tmpfsExists := hostConfig.Tmpfs[bind.Destination]
+		if binds[bind.Destination] || tmpfsExists {
 			return fmt.Errorf("Duplicate mount point '%s'", bind.Destination)
 			return fmt.Errorf("Duplicate mount point '%s'", bind.Destination)
 		}
 		}
 
 

+ 8 - 0
daemon/volumes_unix.go

@@ -16,7 +16,15 @@ import (
 // /etc/resolv.conf, and if it is not, appends it to the array of mounts.
 // /etc/resolv.conf, and if it is not, appends it to the array of mounts.
 func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, error) {
 func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, error) {
 	var mounts []container.Mount
 	var mounts []container.Mount
+	// TODO: tmpfs mounts should be part of Mountpoints
+	tmpfsMounts := make(map[string]bool)
+	for _, m := range c.TmpfsMounts() {
+		tmpfsMounts[m.Destination] = true
+	}
 	for _, m := range c.MountPoints {
 	for _, m := range c.MountPoints {
+		if tmpfsMounts[m.Destination] {
+			continue
+		}
 		if err := daemon.lazyInitializeVolume(c.ID, m); err != nil {
 		if err := daemon.lazyInitializeVolume(c.ID, m); err != nil {
 			return nil, err
 			return nil, err
 		}
 		}

+ 17 - 0
integration-cli/docker_cli_run_unix_test.go

@@ -829,6 +829,23 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) {
 	}
 	}
 }
 }
 
 
+func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) {
+	name := "img-with-volumes"
+	_, err := buildImage(
+		name,
+		`
+    FROM busybox
+    VOLUME /run
+    RUN touch /run/stuff
+    `,
+		true)
+	if err != nil {
+		c.Fatal(err)
+	}
+	out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run")
+	c.Assert(out, checker.Not(checker.Contains), "stuff")
+}
+
 // Test case for #22420
 // Test case for #22420
 func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
 func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)