Browse code

daemon: allow tmpfs to trump over VOLUME(s)

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
(cherry picked from commit 756f6cef4a1379e59d6511ee000e435d23659153)

Antonio Murdaca authored on 2016/06/06 18:57:11
Showing 5 changed files
... ...
@@ -54,7 +54,8 @@ func (container *Container) UnmountVolumes(forceSyscall bool, volumeEventLog fun
54 54
 
55 55
 // TmpfsMounts returns the list of tmpfs mounts
56 56
 func (container *Container) TmpfsMounts() []Mount {
57
-	return nil
57
+	var mounts []Mount
58
+	return mounts
58 59
 }
59 60
 
60 61
 // UpdateContainer updates configuration of a container
... ...
@@ -480,9 +480,10 @@ func setMounts(daemon *Daemon, s *specs.Spec, c *container.Container, mounts []c
480 480
 		}
481 481
 
482 482
 		if m.Source == "tmpfs" {
483
+			data := c.HostConfig.Tmpfs[m.Destination]
483 484
 			options := []string{"noexec", "nosuid", "nodev", volume.DefaultPropagationMode}
484
-			if m.Data != "" {
485
-				options = append(options, strings.Split(m.Data, ",")...)
485
+			if data != "" {
486
+				options = append(options, strings.Split(data, ",")...)
486 487
 			}
487 488
 
488 489
 			merged, err := mount.MergeTmpfsOptions(options)
... ...
@@ -129,7 +129,8 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
129 129
 			return err
130 130
 		}
131 131
 
132
-		if binds[bind.Destination] {
132
+		_, tmpfsExists := hostConfig.Tmpfs[bind.Destination]
133
+		if binds[bind.Destination] || tmpfsExists {
133 134
 			return fmt.Errorf("Duplicate mount point '%s'", bind.Destination)
134 135
 		}
135 136
 
... ...
@@ -16,7 +16,15 @@ import (
16 16
 // /etc/resolv.conf, and if it is not, appends it to the array of mounts.
17 17
 func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, error) {
18 18
 	var mounts []container.Mount
19
+	// TODO: tmpfs mounts should be part of Mountpoints
20
+	tmpfsMounts := make(map[string]bool)
21
+	for _, m := range c.TmpfsMounts() {
22
+		tmpfsMounts[m.Destination] = true
23
+	}
19 24
 	for _, m := range c.MountPoints {
25
+		if tmpfsMounts[m.Destination] {
26
+			continue
27
+		}
20 28
 		if err := daemon.lazyInitializeVolume(c.ID, m); err != nil {
21 29
 			return nil, err
22 30
 		}
... ...
@@ -829,6 +829,23 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) {
829 829
 	}
830 830
 }
831 831
 
832
+func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) {
833
+	name := "img-with-volumes"
834
+	_, err := buildImage(
835
+		name,
836
+		`
837
+    FROM busybox
838
+    VOLUME /run
839
+    RUN touch /run/stuff
840
+    `,
841
+		true)
842
+	if err != nil {
843
+		c.Fatal(err)
844
+	}
845
+	out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run")
846
+	c.Assert(out, checker.Not(checker.Contains), "stuff")
847
+}
848
+
832 849
 // Test case for #22420
833 850
 func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
834 851
 	testRequires(c, DaemonIsLinux)