diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 95188296d8..d17e8093ad 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -403,3 +403,77 @@ func TestDaemonKeyMigration(t *testing.T) { logDone("daemon - key migration") } + +// Simulate an older daemon (pre 1.3) coming up with volumes specified in containers +// without corrosponding volume json +func TestDaemonUpgradeWithVolumes(t *testing.T) { + d := NewDaemon(t) + + graphDir := filepath.Join(os.TempDir(), "docker-test") + defer os.RemoveAll(graphDir) + if err := d.StartWithBusybox("-g", graphDir); err != nil { + t.Fatal(err) + } + + tmpDir := filepath.Join(os.TempDir(), "test") + defer os.RemoveAll(tmpDir) + + if out, err := d.Cmd("create", "-v", tmpDir+":/foo", "--name=test", "busybox"); err != nil { + t.Fatal(err, out) + } + + if err := d.Stop(); err != nil { + t.Fatal(err) + } + + // Remove this since we're expecting the daemon to re-create it too + if err := os.RemoveAll(tmpDir); err != nil { + t.Fatal(err) + } + + configDir := filepath.Join(graphDir, "volumes") + + if err := os.RemoveAll(configDir); err != nil { + t.Fatal(err) + } + + if err := d.Start("-g", graphDir); err != nil { + t.Fatal(err) + } + + if _, err := os.Stat(tmpDir); os.IsNotExist(err) { + t.Fatalf("expected volume path %s to exist but it does not", tmpDir) + } + + dir, err := ioutil.ReadDir(configDir) + if err != nil { + t.Fatal(err) + } + if len(dir) == 0 { + t.Fatalf("expected volumes config dir to contain data for new volume") + } + + // Now with just removing the volume config and not the volume data + if err := d.Stop(); err != nil { + t.Fatal(err) + } + + if err := os.RemoveAll(configDir); err != nil { + t.Fatal(err) + } + + if err := d.Start("-g", graphDir); err != nil { + t.Fatal(err) + } + + dir, err = ioutil.ReadDir(configDir) + if err != nil { + t.Fatal(err) + } + + if len(dir) == 0 { + t.Fatalf("expected volumes config dir to contain data for new volume") + } + + logDone("daemon - volumes from old(pre 1.3) daemon work") +} diff --git a/volumes/repository.go b/volumes/repository.go index 91f98fc060..e125677680 100644 --- a/volumes/repository.go +++ b/volumes/repository.go @@ -57,9 +57,10 @@ func (r *Repository) newVolume(path string, writable bool) (*Volume, error) { } path = filepath.Clean(path) - path, err = filepath.EvalSymlinks(path) - if err != nil { - return nil, err + // Ignore the error here since the path may not exist + // Really just want to make sure the path we are using is real(or non-existant) + if cleanPath, err := filepath.EvalSymlinks(path); err == nil { + path = cleanPath } v := &Volume{