Skip to content

Commit

Permalink
Add option to specify name without --name in volume create
Browse files Browse the repository at this point in the history
Signed-off-by: Kara Alexandra <[email protected]>
  • Loading branch information
ardnaxelarak committed Aug 25, 2016
1 parent 8d99dfb commit ba3f0bf
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 62 deletions.
14 changes: 11 additions & 3 deletions api/client/volume/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ func newCreateCommand(dockerCli *client.DockerCli) *cobra.Command {
}

cmd := &cobra.Command{
Use: "create [OPTIONS]",
Use: "create [OPTIONS] [VOLUME]",
Short: "Create a volume",
Long: createDescription,
Args: cli.NoArgs,
Args: cli.RequiresMaxArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
if opts.name != "" {
fmt.Fprint(dockerCli.Err(), "Conflicting options: either specify --name or provide positional arg, not both\n")
return cli.StatusError{StatusCode: 1}
}
opts.name = args[0]
}
return runCreate(dockerCli, opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.driver, "driver", "d", "local", "Specify volume driver name")
flags.StringVar(&opts.name, "name", "", "Specify volume name")
flags.Lookup("name").Hidden = true
flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options")
flags.StringSliceVar(&opts.labels, "label", []string{}, "Set metadata for a volume")

Expand Down Expand Up @@ -67,7 +75,7 @@ Creates a new volume that containers can consume and store data in. If a name
is not specified, Docker generates a random name. You create a volume and then
configure the container to use it, for example:
$ docker volume create --name hello
$ docker volume create hello
hello
$ docker run -d -v hello:/world busybox ls /world
Expand Down
11 changes: 5 additions & 6 deletions docs/reference/commandline/volume_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ parent = "smn_cli"
# volume create

```markdown
Usage: docker volume create [OPTIONS]
Usage: docker volume create [OPTIONS] [VOLUME]

Create a volume

Options:
-d, --driver string Specify volume driver name (default "local")
--help Print usage
--label value Set metadata for a volume (default [])
--name string Specify volume name
-o, --opt value Set driver specific options (default map[])
```

Creates a new volume that containers can consume and store data in. If a name is not specified, Docker generates a random name. You create a volume and then configure the container to use it, for example:

```bash
$ docker volume create --name hello
$ docker volume create hello
hello

$ docker run -d -v hello:/world busybox ls /world
Expand Down Expand Up @@ -62,19 +61,19 @@ The built-in `local` driver on Linux accepts options similar to the linux `mount
For example, the following creates a `tmpfs` volume called `foo` with a size of 100 megabyte and `uid` of 1000.

```bash
$ docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 --name foo
$ docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 foo
```

Another example that uses `btrfs`:

```bash
$ docker volume create --driver local --opt type=btrfs --opt device=/dev/sda2 --name foo
$ docker volume create --driver local --opt type=btrfs --opt device=/dev/sda2 foo
```

Another example that uses `nfs` to mount the `/path/to/dir` in `rw` mode from `192.168.1.1`:

```bash
$ docker volume create --driver local --opt type=nfs --opt o=addr=192.168.1.1,rw --opt device=:/path/to/dir --name foo
$ docker volume create --driver local --opt type=nfs --opt o=addr=192.168.1.1,rw --opt device=:/path/to/dir foo
```


Expand Down
8 changes: 4 additions & 4 deletions docs/reference/commandline/volume_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Lists all the volumes Docker knows about. You can filter using the `-f` or `--fi
Example output:

```bash
$ docker volume create --name rosemary
$ docker volume create rosemary
rosemary
$docker volume create --name tyler
$docker volume create tyler
tyler
$ docker volume ls
DRIVER VOLUME NAME
Expand Down Expand Up @@ -91,9 +91,9 @@ a `label` and a value.
First, let's create some volumes to illustrate this;

```bash
$ docker volume create --name the-doctor --label is-timelord=yes
$ docker volume create the-doctor --label is-timelord=yes
the-doctor
$ docker volume create --name daleks --label is-timelord=no
$ docker volume create daleks --label is-timelord=no
daleks
```

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/dockervolumes.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ The following example also creates the `my-named-volume` volume, this time
using the `docker volume create` command.

```bash
$ docker volume create -d flocker --name my-named-volume -o size=20GB
$ docker volume create -d flocker my-named-volume -o size=20GB
$ docker run -d -P \
-v my-named-volume:/opt/webapp \
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_daemon_experimental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) {
}
}()

out, err = s.d.Cmd("volume", "create", "-d", pluginName, "--name", volName)
out, err = s.d.Cmd("volume", "create", "-d", pluginName, volName)
if err != nil {
c.Fatalf("Could not create volume: %v %s", err, out)
}
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartRmVolumeInUse(c *check.C) {
func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *check.C) {
c.Assert(s.d.Start(), check.IsNil)

_, err := s.d.Cmd("volume", "create", "--name", "test")
_, err := s.d.Cmd("volume", "create", "test")
c.Assert(err, check.IsNil)
c.Assert(s.d.Restart(), check.IsNil)

Expand Down
6 changes: 3 additions & 3 deletions integration-cli/docker_cli_events_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *DockerSuite) TestVolumeEvents(c *check.C) {
since := daemonUnixTime(c)

// Observe create/mount volume actions
dockerCmd(c, "volume", "create", "--name", "test-event-volume-local")
dockerCmd(c, "volume", "create", "test-event-volume-local")
dockerCmd(c, "run", "--name", "test-volume-container", "--volume", "test-event-volume-local:/foo", "-d", "busybox", "true")
waitRun("test-volume-container")

Expand Down Expand Up @@ -355,7 +355,7 @@ func (s *DockerSuite) TestEventsFilterVolumeAndNetworkType(c *check.C) {
since := daemonUnixTime(c)

dockerCmd(c, "network", "create", "test-event-network-type")
dockerCmd(c, "volume", "create", "--name", "test-event-volume-type")
dockerCmd(c, "volume", "create", "test-event-volume-type")

out, _ := dockerCmd(c, "events", "--filter", "type=volume", "--filter", "type=network", "--since", since, "--until", daemonUnixTime(c))
events := strings.Split(strings.TrimSpace(out), "\n")
Expand All @@ -373,7 +373,7 @@ func (s *DockerSuite) TestEventsFilterVolumeID(c *check.C) {

since := daemonUnixTime(c)

dockerCmd(c, "volume", "create", "--name", "test-event-volume-id")
dockerCmd(c, "volume", "create", "test-event-volume-id")
out, _ := dockerCmd(c, "events", "--filter", "volume=test-event-volume-id", "--since", since, "--until", daemonUnixTime(c))
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 1)
Expand Down
14 changes: 7 additions & 7 deletions integration-cli/docker_cli_external_volume_driver_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyE
}

func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *check.C) {
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "--name", "foo")
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "foo")
dockerCmd(c, "run", "-d", "--name", "testing", "-v", "foo:/bar", "busybox", "top")

var mounts []struct {
Expand All @@ -424,7 +424,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c
}

func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverList(c *check.C) {
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "--name", "abc3")
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "abc3")
out, _ := dockerCmd(c, "volume", "ls")
ls := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(ls), check.Equals, 2, check.Commentf("\n%s", out))
Expand All @@ -443,7 +443,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *check.C) {
c.Assert(s.ec.gets, check.Equals, 1)
c.Assert(out, checker.Contains, "No such volume")

dockerCmd(c, "volume", "create", "--name", "test", "-d", "test-external-volume-driver")
dockerCmd(c, "volume", "create", "test", "-d", "test-external-volume-driver")
out, _ = dockerCmd(c, "volume", "inspect", "test")

type vol struct {
Expand All @@ -458,7 +458,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *check.C) {
}

func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c *check.C) {
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "--name", "abc1")
dockerCmd(c, "volume", "create", "-d", "test-external-volume-driver", "abc1")
err := s.d.Restart()
c.Assert(err, checker.IsNil)

Expand All @@ -474,7 +474,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *check.C) {
c.Assert(s.d.Start(), checker.IsNil)

out, err := s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--name", "abc2", "--opt", "ninja=1")
out, err := s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "abc2", "--opt", "ninja=1")
c.Assert(err, checker.IsNil, check.Commentf(out))

out, err = s.d.Cmd("volume", "inspect", "abc2")
Expand All @@ -487,7 +487,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverPathCalls(c *check.C
c.Assert(s.d.Start(), checker.IsNil)
c.Assert(s.ec.paths, checker.Equals, 0)

out, err := s.d.Cmd("volume", "create", "--name=test", "--driver=test-external-volume-driver")
out, err := s.d.Cmd("volume", "create", "test", "--driver=test-external-volume-driver")
c.Assert(err, checker.IsNil, check.Commentf(out))
c.Assert(s.ec.paths, checker.Equals, 1)

Expand Down Expand Up @@ -516,7 +516,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverCapabilities(c *chec
c.Assert(s.ec.caps, checker.Equals, 0)

for i := 0; i < 3; i++ {
out, err := s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--name", fmt.Sprintf("test%d", i))
out, err := s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", fmt.Sprintf("test%d", i))
c.Assert(err, checker.IsNil, check.Commentf(out))
c.Assert(s.ec.caps, checker.Equals, 1)
out, err = s.d.Cmd("volume", "inspect", "--format={{.Scope}}", fmt.Sprintf("test%d", i))
Expand Down
11 changes: 6 additions & 5 deletions integration-cli/docker_cli_help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,12 @@ func testCommand(cmd string, newEnvs []string, scanForHome bool, home string) er

// These commands will never print a short-usage so don't test
noShortUsage := map[string]string{
"images": "",
"login": "",
"logout": "",
"network": "",
"stats": "",
"images": "",
"login": "",
"logout": "",
"network": "",
"stats": "",
"volume create": "",
}

if _, ok := noShortUsage[cmd]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {

mp := prefix + slash + "test"

dockerCmd(c, "volume", "create", "--name", "ps-volume-test")
dockerCmd(c, "volume", "create", "ps-volume-test")
// volume mount containers
runSleepingContainer(c, "--name=volume-test-1", "--volume", "ps-volume-test:"+mp)
c.Assert(waitRun("volume-test-1"), checker.IsNil)
Expand Down
6 changes: 3 additions & 3 deletions integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4307,7 +4307,7 @@ func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) {
func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) {
prefix, _ := getPrefixAndSlashFromDaemonPlatform()

dockerCmd(c, "volume", "create", "--name", "test")
dockerCmd(c, "volume", "create", "test")

dockerCmd(c, "run", "--rm", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true")
dockerCmd(c, "volume", "inspect", "test")
Expand All @@ -4324,7 +4324,7 @@ func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) {
func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) {
prefix, _ := getPrefixAndSlashFromDaemonPlatform()

dockerCmd(c, "volume", "create", "--name", "test")
dockerCmd(c, "volume", "create", "test")
dockerCmd(c, "run", "--name=parent", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true")
dockerCmd(c, "run", "--name=child", "--volumes-from=parent", "busybox", "true")

Expand Down Expand Up @@ -4381,7 +4381,7 @@ func (s *DockerSuite) TestRunVolumeCopyFlag(c *check.C) {
)
c.Assert(err, checker.IsNil)

dockerCmd(c, "volume", "create", "--name=test")
dockerCmd(c, "volume", "create", "test")

// test with the nocopy flag
out, _, err := dockerCmdWithError("run", "-v", "test:/foo:nocopy", "volumecopy")
Expand Down
Loading

0 comments on commit ba3f0bf

Please sign in to comment.