2016-10-14 18:30:36 -04:00
|
|
|
---
|
|
|
|
title: "volume create"
|
|
|
|
description: "The volume create command description and usage"
|
2016-11-03 18:48:30 -04:00
|
|
|
keywords: "volume, create"
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2015-06-12 09:25:32 -04:00
|
|
|
|
|
|
|
# volume create
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
```markdown
|
2016-06-14 18:42:30 -04:00
|
|
|
Usage: docker volume create [OPTIONS] [VOLUME]
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
Create a volume
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
Options:
|
|
|
|
-d, --driver string Specify volume driver name (default "local")
|
|
|
|
--help Print usage
|
|
|
|
--label value Set metadata for a volume (default [])
|
|
|
|
-o, --opt value Set driver specific options (default map[])
|
|
|
|
```
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Description
|
|
|
|
|
|
|
|
Creates a new volume that containers can consume and store data in. If a name is
|
|
|
|
not specified, Docker generates a random name.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
Create a volume and then configure the container to use it:
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-06-14 18:42:30 -04:00
|
|
|
$ docker volume create hello
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2016-02-11 21:48:16 -05:00
|
|
|
hello
|
2015-11-09 03:17:50 -05:00
|
|
|
|
2016-02-11 21:48:16 -05:00
|
|
|
$ docker run -d -v hello:/world busybox ls /world
|
|
|
|
```
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
The mount is created inside the container's `/world` directory. Docker does not
|
|
|
|
support relative paths for mount points inside the container.
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
Multiple containers can use the same volume in the same time period. This is
|
|
|
|
useful if two containers need access to shared data. For example, if one
|
|
|
|
container writes and the other reads the data.
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
Volume names must be unique among drivers. This means you cannot use the same
|
|
|
|
volume name with two different drivers. If you attempt this `docker` returns an
|
|
|
|
error:
|
2015-10-04 08:09:51 -04:00
|
|
|
|
2020-05-11 11:32:52 -04:00
|
|
|
```console
|
2015-10-29 22:48:56 -04:00
|
|
|
A volume named "hello" already exists with the "some-other" driver. Choose a different volume name.
|
2015-10-04 08:09:51 -04:00
|
|
|
```
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
If you specify a volume name already in use on the current driver, Docker
|
|
|
|
assumes you want to re-use the existing volume and does not return an error.
|
2015-10-04 08:09:51 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### Driver-specific options
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
Some volume drivers may take options to customize the volume creation. Use the
|
|
|
|
`-o` or `--opt` flags to pass driver options:
|
2015-06-12 09:25:32 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
$ docker volume create --driver fake \
|
|
|
|
--opt tardis=blue \
|
|
|
|
--opt timey=wimey \
|
|
|
|
foo
|
2016-02-11 21:48:16 -05:00
|
|
|
```
|
2015-06-12 09:25:32 -04:00
|
|
|
|
|
|
|
These options are passed directly to the volume driver. Options for
|
|
|
|
different volume drivers may do different things (or nothing at all).
|
|
|
|
|
2016-02-11 21:48:16 -05:00
|
|
|
The built-in `local` driver on Windows does not support any options.
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
The built-in `local` driver on Linux accepts options similar to the linux
|
|
|
|
`mount` command. You can provide multiple options by passing the `--opt` flag
|
|
|
|
multiple times. Some `mount` options (such as the `o` option) can take a
|
|
|
|
comma-separated list of options. Complete list of available mount options can be
|
|
|
|
found [here](http://man7.org/linux/man-pages/man8/mount.8.html).
|
2016-10-14 18:30:36 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
For example, the following creates a `tmpfs` volume called `foo` with a size of
|
|
|
|
100 megabyte and `uid` of 1000.
|
2016-02-11 21:48:16 -05:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
$ docker volume create --driver local \
|
|
|
|
--opt type=tmpfs \
|
|
|
|
--opt device=tmpfs \
|
|
|
|
--opt o=size=100m,uid=1000 \
|
|
|
|
foo
|
2016-02-11 21:48:16 -05:00
|
|
|
```
|
|
|
|
|
2016-06-29 21:11:41 -04:00
|
|
|
Another example that uses `btrfs`:
|
2016-02-11 21:48:16 -05:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
$ docker volume create --driver local \
|
|
|
|
--opt type=btrfs \
|
|
|
|
--opt device=/dev/sda2 \
|
|
|
|
foo
|
2016-06-29 21:11:41 -04:00
|
|
|
```
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
Another example that uses `nfs` to mount the `/path/to/dir` in `rw` mode from
|
|
|
|
`192.168.1.1`:
|
2016-06-29 21:11:41 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
$ docker volume create --driver local \
|
|
|
|
--opt type=nfs \
|
|
|
|
--opt o=addr=192.168.1.1,rw \
|
|
|
|
--opt device=:/path/to/dir \
|
|
|
|
foo
|
2016-02-11 21:48:16 -05:00
|
|
|
```
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Related commands
|
2016-02-18 14:52:15 -05:00
|
|
|
|
|
|
|
* [volume inspect](volume_inspect.md)
|
|
|
|
* [volume ls](volume_ls.md)
|
|
|
|
* [volume rm](volume_rm.md)
|
2016-10-18 06:50:11 -04:00
|
|
|
* [volume prune](volume_prune.md)
|
2020-04-19 09:43:08 -04:00
|
|
|
* [Understand Data Volumes](https://docs.docker.com/storage/volumes/)
|