Make lxc driver rbind all user specified mounts.
| ... | ... |
@@ -75,9 +75,9 @@ lxc.mount.entry = shm {{escapeFstabSpaces $ROOTFS}}/dev/shm tmpfs {{formatMountL
|
| 75 | 75 |
|
| 76 | 76 |
{{range $value := .Mounts}}
|
| 77 | 77 |
{{if $value.Writable}}
|
| 78 |
-lxc.mount.entry = {{$value.Source}} {{escapeFstabSpaces $ROOTFS}}/{{escapeFstabSpaces $value.Destination}} none bind,rw 0 0
|
|
| 78 |
+lxc.mount.entry = {{$value.Source}} {{escapeFstabSpaces $ROOTFS}}/{{escapeFstabSpaces $value.Destination}} none rbind,rw 0 0
|
|
| 79 | 79 |
{{else}}
|
| 80 |
-lxc.mount.entry = {{$value.Source}} {{escapeFstabSpaces $ROOTFS}}/{{escapeFstabSpaces $value.Destination}} none bind,ro 0 0
|
|
| 80 |
+lxc.mount.entry = {{$value.Source}} {{escapeFstabSpaces $ROOTFS}}/{{escapeFstabSpaces $value.Destination}} none rbind,ro 0 0
|
|
| 81 | 81 |
{{end}}
|
| 82 | 82 |
{{end}}
|
| 83 | 83 |
|
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"io/ioutil" |
| 6 | 6 |
"os" |
| 7 | 7 |
"os/exec" |
| 8 |
+ "path/filepath" |
|
| 8 | 9 |
"reflect" |
| 9 | 10 |
"regexp" |
| 10 | 11 |
"sort" |
| ... | ... |
@@ -12,6 +13,7 @@ import ( |
| 12 | 12 |
"sync" |
| 13 | 13 |
"testing" |
| 14 | 14 |
|
| 15 |
+ "github.com/docker/docker/pkg/mount" |
|
| 15 | 16 |
"github.com/docker/docker/pkg/networkfs/resolvconf" |
| 16 | 17 |
) |
| 17 | 18 |
|
| ... | ... |
@@ -1142,6 +1144,44 @@ func TestDisallowBindMountingRootToRoot(t *testing.T) {
|
| 1142 | 1142 |
logDone("run - bind mount /:/ as volume should fail")
|
| 1143 | 1143 |
} |
| 1144 | 1144 |
|
| 1145 |
+// Test recursive bind mount works by default |
|
| 1146 |
+func TestDockerRunWithVolumesIsRecursive(t *testing.T) {
|
|
| 1147 |
+ tmpDir, err := ioutil.TempDir("", "docker_recursive_mount_test")
|
|
| 1148 |
+ if err != nil {
|
|
| 1149 |
+ t.Fatal(err) |
|
| 1150 |
+ } |
|
| 1151 |
+ |
|
| 1152 |
+ defer os.RemoveAll(tmpDir) |
|
| 1153 |
+ |
|
| 1154 |
+ // Create a temporary tmpfs mount. |
|
| 1155 |
+ tmpfsDir := filepath.Join(tmpDir, "tmpfs") |
|
| 1156 |
+ if err := os.MkdirAll(tmpfsDir, 0777); err != nil {
|
|
| 1157 |
+ t.Fatalf("failed to mkdir at %s - %s", tmpfsDir, err)
|
|
| 1158 |
+ } |
|
| 1159 |
+ if err := mount.Mount("tmpfs", tmpfsDir, "tmpfs", ""); err != nil {
|
|
| 1160 |
+ t.Fatalf("failed to create a tmpfs mount at %s - %s", tmpfsDir, err)
|
|
| 1161 |
+ } |
|
| 1162 |
+ |
|
| 1163 |
+ f, err := ioutil.TempFile(tmpfsDir, "touch-me") |
|
| 1164 |
+ if err != nil {
|
|
| 1165 |
+ t.Fatal(err) |
|
| 1166 |
+ } |
|
| 1167 |
+ defer f.Close() |
|
| 1168 |
+ |
|
| 1169 |
+ runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
|
|
| 1170 |
+ out, stderr, exitCode, err := runCommandWithStdoutStderr(runCmd) |
|
| 1171 |
+ if err != nil && exitCode != 0 {
|
|
| 1172 |
+ t.Fatal(out, stderr, err) |
|
| 1173 |
+ } |
|
| 1174 |
+ if !strings.Contains(out, filepath.Base(f.Name())) {
|
|
| 1175 |
+ t.Fatal("Recursive bind mount test failed. Expected file not found")
|
|
| 1176 |
+ } |
|
| 1177 |
+ |
|
| 1178 |
+ deleteAllContainers() |
|
| 1179 |
+ |
|
| 1180 |
+ logDone("run - volumes are bind mounted recuursively")
|
|
| 1181 |
+} |
|
| 1182 |
+ |
|
| 1145 | 1183 |
func TestDnsDefaultOptions(t *testing.T) {
|
| 1146 | 1184 |
cmd := exec.Command(dockerBinary, "run", "busybox", "cat", "/etc/resolv.conf") |
| 1147 | 1185 |
|