From 6a8ea46c67c3594118c7da41b1cebe062aff3f6a Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 26 Apr 2016 10:20:17 +0200 Subject: [PATCH] daemon: reorder mounts before setting them Signed-off-by: Antonio Murdaca --- daemon/oci_linux.go | 10 ++++++---- integration-cli/docker_cli_run_unix_test.go | 12 +++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go index bb60efe89c..0110ac26ee 100644 --- a/daemon/oci_linux.go +++ b/daemon/oci_linux.go @@ -5,6 +5,7 @@ import ( "io" "os" "path/filepath" + "sort" "strconv" "strings" @@ -635,13 +636,14 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e return nil, err } - mounts, err := daemon.setupMounts(c) + ms, err := daemon.setupMounts(c) if err != nil { return nil, err } - mounts = append(mounts, c.IpcMounts()...) - mounts = append(mounts, c.TmpfsMounts()...) - if err := setMounts(daemon, &s, c, mounts); err != nil { + ms = append(ms, c.IpcMounts()...) + ms = append(ms, c.TmpfsMounts()...) + sort.Sort(mounts(ms)) + if err := setMounts(daemon, &s, c, ms); err != nil { return nil, fmt.Errorf("linux mounts: %v", err) } diff --git a/integration-cli/docker_cli_run_unix_test.go b/integration-cli/docker_cli_run_unix_test.go index 542e856182..8283272351 100644 --- a/integration-cli/docker_cli_run_unix_test.go +++ b/integration-cli/docker_cli_run_unix_test.go @@ -746,6 +746,14 @@ func (s *DockerSuite) TestRunWithShmSize(c *check.C) { c.Assert(shmSize, check.Equals, "1073741824") } +func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *check.C) { + tmpFile, err := ioutil.TempFile("", "test") + c.Assert(err, check.IsNil) + defer tmpFile.Close() + out, _ := dockerCmd(c, "run", "--tmpfs", "/run", "-v", tmpFile.Name()+":/run/test", "busybox", "ls", "/run") + c.Assert(out, checker.Contains, "test") +} + func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) { // TODO Windows (Post TP5): This test cannot run on a Windows daemon as // Windows does not support tmpfs mounts. @@ -839,10 +847,8 @@ func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *check.C) { ] }` tmpFile, err := ioutil.TempFile("", "profile.json") + c.Assert(err, check.IsNil) defer tmpFile.Close() - if err != nil { - c.Fatal(err) - } if _, err := tmpFile.Write([]byte(jsonData)); err != nil { c.Fatal(err)