diff --git a/commands.go b/commands.go index ef6dce6bd5..4fed585062 100644 --- a/commands.go +++ b/commands.go @@ -1814,6 +1814,8 @@ func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Co flVolumes.Set(dstDir) binds = append(binds, bind) flVolumes.Delete(bind) + } else if bind == "/" { + return nil, nil, cmd, fmt.Errorf("Invalid volume: path can't be '/'") } } diff --git a/commands_unit_test.go b/commands_unit_test.go index 2eac5ce60d..e44d9a1854 100644 --- a/commands_unit_test.go +++ b/commands_unit_test.go @@ -128,7 +128,9 @@ func TestParseRunVolumes(t *testing.T) { t.Fatalf("Error parsing volume flags, without volume, no volume should be present. Received %v", config.Volumes) } - mustParse(t, "-v /") + if _, _, err := parse(t, "-v /"); err == nil { + t.Fatalf("Expected error, but got none") + } if _, _, err := parse(t, "-v /:/"); err == nil { t.Fatalf("Error parsing volume flags, `-v /:/` should fail but didn't") diff --git a/container.go b/container.go index 206f2dfe63..0524080370 100644 --- a/container.go +++ b/container.go @@ -836,7 +836,7 @@ func (container *Container) createVolumes() error { volPath = path.Join(container.RootfsPath(), volPath) rootVolPath, err := utils.FollowSymlinkInScope(volPath, container.RootfsPath()) if err != nil { - panic(err) + return err } if _, err := os.Stat(rootVolPath); err != nil {