mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add a cli integration test for recursive bind mounting.
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
parent
d82bb603af
commit
3e1c1567ea
2 changed files with 40 additions and 17 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/mount"
|
||||||
"github.com/docker/docker/pkg/networkfs/resolvconf"
|
"github.com/docker/docker/pkg/networkfs/resolvconf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1142,6 +1144,44 @@ func TestDisallowBindMountingRootToRoot(t *testing.T) {
|
||||||
logDone("run - bind mount /:/ as volume should fail")
|
logDone("run - bind mount /:/ as volume should fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test recursive bind mount works by default
|
||||||
|
func TestDockerRunWithVolumesIsRecursive(t *testing.T) {
|
||||||
|
tmpDir, err := ioutil.TempDir("", "docker_recursive_mount_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
// Create a temporary tmpfs mount.
|
||||||
|
tmpfsDir := filepath.Join(tmpDir, "tmpfs")
|
||||||
|
if err := os.MkdirAll(tmpfsDir, 0777); err != nil {
|
||||||
|
t.Fatalf("failed to mkdir at %s - %s", tmpfsDir, err)
|
||||||
|
}
|
||||||
|
if err := mount.Mount("tmpfs", tmpfsDir, "tmpfs", ""); err != nil {
|
||||||
|
t.Fatalf("failed to create a tmpfs mount at %s - %s", tmpfsDir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := ioutil.TempFile(tmpfsDir, "touch-me")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
|
||||||
|
out, stderr, exitCode, err := runCommandWithStdoutStderr(runCmd)
|
||||||
|
if err != nil && exitCode != 0 {
|
||||||
|
t.Fatal(out, stderr, err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, filepath.Base(f.Name())) {
|
||||||
|
t.Fatal("Recursive bind mount test failed. Expected file not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAllContainers()
|
||||||
|
|
||||||
|
logDone("run - volumes are bind mounted recuursively")
|
||||||
|
}
|
||||||
|
|
||||||
func TestDnsDefaultOptions(t *testing.T) {
|
func TestDnsDefaultOptions(t *testing.T) {
|
||||||
cmd := exec.Command(dockerBinary, "run", "busybox", "cat", "/etc/resolv.conf")
|
cmd := exec.Command(dockerBinary, "run", "busybox", "cat", "/etc/resolv.conf")
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,10 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/mount"
|
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -387,21 +385,6 @@ func TestBindMounts(t *testing.T) {
|
||||||
t.Fatal("Container failed to read from bind mount")
|
t.Fatal("Container failed to read from bind mount")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test recursive bind mount works by default
|
|
||||||
// Create a temporary tmpfs mount.
|
|
||||||
tmpfsDir := filepath.Join(tmpDir, "tmpfs")
|
|
||||||
if err := os.MkdirAll(tmpfsDir, 0777); err != nil {
|
|
||||||
t.Fatalf("failed to mkdir at %s - %s", tmpfsDir, err)
|
|
||||||
}
|
|
||||||
if err := mount.Mount("tmpfs", tmpfsDir, "tmpfs", ""); err != nil {
|
|
||||||
t.Fatalf("failed to create a tmpfs mount at %s - %s", tmpfsDir, err)
|
|
||||||
}
|
|
||||||
writeFile(path.Join(tmpfsDir, "touch-me-again"), "", t)
|
|
||||||
stdout, _ = runContainer(eng, r, []string{"-v", fmt.Sprintf("%s:/tmp:ro", tmpDir), "_", "ls", "/tmp/tmpfs"}, t)
|
|
||||||
if !strings.Contains(stdout, "touch-me-again") {
|
|
||||||
t.Fatal("Container recursive bind mount test failed. Expected file not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
// test writing to bind mount
|
// test writing to bind mount
|
||||||
runContainer(eng, r, []string{"-v", fmt.Sprintf("%s:/tmp:rw", tmpDir), "_", "touch", "/tmp/holla"}, t)
|
runContainer(eng, r, []string{"-v", fmt.Sprintf("%s:/tmp:rw", tmpDir), "_", "touch", "/tmp/holla"}, t)
|
||||||
readFile(path.Join(tmpDir, "holla"), t) // Will fail if the file doesn't exist
|
readFile(path.Join(tmpDir, "holla"), t) // Will fail if the file doesn't exist
|
||||||
|
|
Loading…
Add table
Reference in a new issue