Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
| ... | ... |
@@ -34,7 +34,6 @@ import ( |
| 34 | 34 |
"github.com/docker/go-connections/nat" |
| 35 | 35 |
"github.com/docker/libnetwork/resolvconf" |
| 36 | 36 |
"github.com/docker/libnetwork/types" |
| 37 |
- "github.com/moby/sys/mount" |
|
| 38 | 37 |
"github.com/moby/sys/mountinfo" |
| 39 | 38 |
"gotest.tools/v3/assert" |
| 40 | 39 |
"gotest.tools/v3/icmd" |
| ... | ... |
@@ -3764,86 +3763,6 @@ func (s *DockerSuite) TestRunWithOomScoreAdjInvalidRange(c *testing.T) {
|
| 3764 | 3764 |
} |
| 3765 | 3765 |
} |
| 3766 | 3766 |
|
| 3767 |
-func (s *DockerSuite) TestRunVolumesMountedAsShared(c *testing.T) {
|
|
| 3768 |
- // Volume propagation is linux only. Also it creates directories for |
|
| 3769 |
- // bind mounting, so needs to be same host. |
|
| 3770 |
- testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace) |
|
| 3771 |
- |
|
| 3772 |
- // Prepare a source directory to bind mount |
|
| 3773 |
- tmpDir, err := ioutil.TempDir("", "volume-source")
|
|
| 3774 |
- if err != nil {
|
|
| 3775 |
- c.Fatal(err) |
|
| 3776 |
- } |
|
| 3777 |
- defer os.RemoveAll(tmpDir) |
|
| 3778 |
- |
|
| 3779 |
- if err := os.Mkdir(path.Join(tmpDir, "mnt1"), 0755); err != nil {
|
|
| 3780 |
- c.Fatal(err) |
|
| 3781 |
- } |
|
| 3782 |
- |
|
| 3783 |
- // Convert this directory into a shared mount point so that we do |
|
| 3784 |
- // not rely on propagation properties of parent mount. |
|
| 3785 |
- icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
|
|
| 3786 |
- icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
|
|
| 3787 |
- |
|
| 3788 |
- dockerCmd(c, "run", "--privileged", "-v", fmt.Sprintf("%s:/volume-dest:shared", tmpDir), "busybox", "mount", "--bind", "/volume-dest/mnt1", "/volume-dest/mnt1")
|
|
| 3789 |
- |
|
| 3790 |
- // Make sure a bind mount under a shared volume propagated to host. |
|
| 3791 |
- if mounted, _ := mountinfo.Mounted(path.Join(tmpDir, "mnt1")); !mounted {
|
|
| 3792 |
- c.Fatalf("Bind mount under shared volume did not propagate to host")
|
|
| 3793 |
- } |
|
| 3794 |
- |
|
| 3795 |
- mount.Unmount(path.Join(tmpDir, "mnt1")) |
|
| 3796 |
-} |
|
| 3797 |
- |
|
| 3798 |
-func (s *DockerSuite) TestRunVolumesMountedAsSlave(c *testing.T) {
|
|
| 3799 |
- // Volume propagation is linux only. Also it creates directories for |
|
| 3800 |
- // bind mounting, so needs to be same host. |
|
| 3801 |
- testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace) |
|
| 3802 |
- |
|
| 3803 |
- // Prepare a source directory to bind mount |
|
| 3804 |
- tmpDir, err := ioutil.TempDir("", "volume-source")
|
|
| 3805 |
- if err != nil {
|
|
| 3806 |
- c.Fatal(err) |
|
| 3807 |
- } |
|
| 3808 |
- defer os.RemoveAll(tmpDir) |
|
| 3809 |
- |
|
| 3810 |
- if err := os.Mkdir(path.Join(tmpDir, "mnt1"), 0755); err != nil {
|
|
| 3811 |
- c.Fatal(err) |
|
| 3812 |
- } |
|
| 3813 |
- |
|
| 3814 |
- // Prepare a source directory with file in it. We will bind mount this |
|
| 3815 |
- // directory and see if file shows up. |
|
| 3816 |
- tmpDir2, err := ioutil.TempDir("", "volume-source2")
|
|
| 3817 |
- if err != nil {
|
|
| 3818 |
- c.Fatal(err) |
|
| 3819 |
- } |
|
| 3820 |
- defer os.RemoveAll(tmpDir2) |
|
| 3821 |
- |
|
| 3822 |
- if err := ioutil.WriteFile(path.Join(tmpDir2, "slave-testfile"), []byte("Test"), 0644); err != nil {
|
|
| 3823 |
- c.Fatal(err) |
|
| 3824 |
- } |
|
| 3825 |
- |
|
| 3826 |
- // Convert this directory into a shared mount point so that we do |
|
| 3827 |
- // not rely on propagation properties of parent mount. |
|
| 3828 |
- icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
|
|
| 3829 |
- icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
|
|
| 3830 |
- |
|
| 3831 |
- dockerCmd(c, "run", "-i", "-d", "--name", "parent", "-v", fmt.Sprintf("%s:/volume-dest:slave", tmpDir), "busybox", "top")
|
|
| 3832 |
- |
|
| 3833 |
- // Bind mount tmpDir2/ onto tmpDir/mnt1. If mount propagates inside |
|
| 3834 |
- // container then contents of tmpDir2/slave-testfile should become |
|
| 3835 |
- // visible at "/volume-dest/mnt1/slave-testfile" |
|
| 3836 |
- icmd.RunCommand("mount", "--bind", tmpDir2, path.Join(tmpDir, "mnt1")).Assert(c, icmd.Success)
|
|
| 3837 |
- |
|
| 3838 |
- out, _ := dockerCmd(c, "exec", "parent", "cat", "/volume-dest/mnt1/slave-testfile") |
|
| 3839 |
- |
|
| 3840 |
- mount.Unmount(path.Join(tmpDir, "mnt1")) |
|
| 3841 |
- |
|
| 3842 |
- if out != "Test" {
|
|
| 3843 |
- c.Fatalf("Bind mount under slave volume did not propagate to container")
|
|
| 3844 |
- } |
|
| 3845 |
-} |
|
| 3846 |
- |
|
| 3847 | 3767 |
func (s *DockerSuite) TestRunNamedVolumesMountedAsShared(c *testing.T) {
|
| 3848 | 3768 |
testRequires(c, DaemonIsLinux, NotUserNamespace) |
| 3849 | 3769 |
out, exitCode, _ := dockerCmdWithError("run", "-v", "foo:/test:shared", "busybox", "touch", "/test/somefile")
|
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"io/ioutil" |
| 11 | 11 |
"os" |
| 12 | 12 |
"os/exec" |
| 13 |
+ "path" |
|
| 13 | 14 |
"path/filepath" |
| 14 | 15 |
"regexp" |
| 15 | 16 |
"strconv" |
| ... | ... |
@@ -26,6 +27,7 @@ import ( |
| 26 | 26 |
"github.com/docker/docker/pkg/parsers" |
| 27 | 27 |
"github.com/docker/docker/pkg/sysinfo" |
| 28 | 28 |
"github.com/moby/sys/mount" |
| 29 |
+ "github.com/moby/sys/mountinfo" |
|
| 29 | 30 |
"gotest.tools/v3/assert" |
| 30 | 31 |
"gotest.tools/v3/icmd" |
| 31 | 32 |
) |
| ... | ... |
@@ -1599,3 +1601,83 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *testing.T) {
|
| 1599 | 1599 |
assert.ErrorContains(c, err, "") |
| 1600 | 1600 |
assert.Assert(c, strings.Contains(out, "Conflicting options: Nano CPUs and CPU Period cannot both be set")) |
| 1601 | 1601 |
} |
| 1602 |
+ |
|
| 1603 |
+func (s *DockerSuite) TestRunVolumesMountedAsShared(c *testing.T) {
|
|
| 1604 |
+ // Volume propagation is linux only. Also it creates directories for |
|
| 1605 |
+ // bind mounting, so needs to be same host. |
|
| 1606 |
+ testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace) |
|
| 1607 |
+ |
|
| 1608 |
+ // Prepare a source directory to bind mount |
|
| 1609 |
+ tmpDir, err := ioutil.TempDir("", "volume-source")
|
|
| 1610 |
+ if err != nil {
|
|
| 1611 |
+ c.Fatal(err) |
|
| 1612 |
+ } |
|
| 1613 |
+ defer os.RemoveAll(tmpDir) |
|
| 1614 |
+ |
|
| 1615 |
+ if err := os.Mkdir(path.Join(tmpDir, "mnt1"), 0755); err != nil {
|
|
| 1616 |
+ c.Fatal(err) |
|
| 1617 |
+ } |
|
| 1618 |
+ |
|
| 1619 |
+ // Convert this directory into a shared mount point so that we do |
|
| 1620 |
+ // not rely on propagation properties of parent mount. |
|
| 1621 |
+ icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
|
|
| 1622 |
+ icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
|
|
| 1623 |
+ |
|
| 1624 |
+ dockerCmd(c, "run", "--privileged", "-v", fmt.Sprintf("%s:/volume-dest:shared", tmpDir), "busybox", "mount", "--bind", "/volume-dest/mnt1", "/volume-dest/mnt1")
|
|
| 1625 |
+ |
|
| 1626 |
+ // Make sure a bind mount under a shared volume propagated to host. |
|
| 1627 |
+ if mounted, _ := mountinfo.Mounted(path.Join(tmpDir, "mnt1")); !mounted {
|
|
| 1628 |
+ c.Fatalf("Bind mount under shared volume did not propagate to host")
|
|
| 1629 |
+ } |
|
| 1630 |
+ |
|
| 1631 |
+ mount.Unmount(path.Join(tmpDir, "mnt1")) |
|
| 1632 |
+} |
|
| 1633 |
+ |
|
| 1634 |
+func (s *DockerSuite) TestRunVolumesMountedAsSlave(c *testing.T) {
|
|
| 1635 |
+ // Volume propagation is linux only. Also it creates directories for |
|
| 1636 |
+ // bind mounting, so needs to be same host. |
|
| 1637 |
+ testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon, NotUserNamespace) |
|
| 1638 |
+ |
|
| 1639 |
+ // Prepare a source directory to bind mount |
|
| 1640 |
+ tmpDir, err := ioutil.TempDir("", "volume-source")
|
|
| 1641 |
+ if err != nil {
|
|
| 1642 |
+ c.Fatal(err) |
|
| 1643 |
+ } |
|
| 1644 |
+ defer os.RemoveAll(tmpDir) |
|
| 1645 |
+ |
|
| 1646 |
+ if err := os.Mkdir(path.Join(tmpDir, "mnt1"), 0755); err != nil {
|
|
| 1647 |
+ c.Fatal(err) |
|
| 1648 |
+ } |
|
| 1649 |
+ |
|
| 1650 |
+ // Prepare a source directory with file in it. We will bind mount this |
|
| 1651 |
+ // directory and see if file shows up. |
|
| 1652 |
+ tmpDir2, err := ioutil.TempDir("", "volume-source2")
|
|
| 1653 |
+ if err != nil {
|
|
| 1654 |
+ c.Fatal(err) |
|
| 1655 |
+ } |
|
| 1656 |
+ defer os.RemoveAll(tmpDir2) |
|
| 1657 |
+ |
|
| 1658 |
+ if err := ioutil.WriteFile(path.Join(tmpDir2, "slave-testfile"), []byte("Test"), 0644); err != nil {
|
|
| 1659 |
+ c.Fatal(err) |
|
| 1660 |
+ } |
|
| 1661 |
+ |
|
| 1662 |
+ // Convert this directory into a shared mount point so that we do |
|
| 1663 |
+ // not rely on propagation properties of parent mount. |
|
| 1664 |
+ icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
|
|
| 1665 |
+ icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
|
|
| 1666 |
+ |
|
| 1667 |
+ dockerCmd(c, "run", "-i", "-d", "--name", "parent", "-v", fmt.Sprintf("%s:/volume-dest:slave", tmpDir), "busybox", "top")
|
|
| 1668 |
+ |
|
| 1669 |
+ // Bind mount tmpDir2/ onto tmpDir/mnt1. If mount propagates inside |
|
| 1670 |
+ // container then contents of tmpDir2/slave-testfile should become |
|
| 1671 |
+ // visible at "/volume-dest/mnt1/slave-testfile" |
|
| 1672 |
+ icmd.RunCommand("mount", "--bind", tmpDir2, path.Join(tmpDir, "mnt1")).Assert(c, icmd.Success)
|
|
| 1673 |
+ |
|
| 1674 |
+ out, _ := dockerCmd(c, "exec", "parent", "cat", "/volume-dest/mnt1/slave-testfile") |
|
| 1675 |
+ |
|
| 1676 |
+ mount.Unmount(path.Join(tmpDir, "mnt1")) |
|
| 1677 |
+ |
|
| 1678 |
+ if out != "Test" {
|
|
| 1679 |
+ c.Fatalf("Bind mount under slave volume did not propagate to container")
|
|
| 1680 |
+ } |
|
| 1681 |
+} |