2016-10-14 18:30:36 -04:00
|
|
|
---
|
|
|
|
title: "Volume plugins"
|
|
|
|
description: "How to manage data with external volume plugins"
|
2016-11-03 17:21:33 -04:00
|
|
|
keywords: "Examples, Usage, volume, docker, data, volumes, plugin, api"
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2015-07-15 14:25:56 -04:00
|
|
|
|
2016-10-19 13:25:45 -04:00
|
|
|
<!-- This file is maintained within the docker/docker Github
|
|
|
|
repository at https://github.com/docker/docker/. Make all
|
|
|
|
pull requests against that repo. If you see this file in
|
|
|
|
another repository, consider it read-only there, as it will
|
|
|
|
periodically be overwritten by the definitive file. Pull
|
|
|
|
requests which include edits to this file in other repositories
|
|
|
|
will be rejected.
|
|
|
|
-->
|
|
|
|
|
2015-07-15 14:25:56 -04:00
|
|
|
# Write a volume plugin
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2016-01-23 23:36:40 -05:00
|
|
|
Docker Engine volume plugins enable Engine deployments to be integrated with
|
2017-01-27 19:51:44 -05:00
|
|
|
external storage systems such as Amazon EBS, and enable data volumes to persist
|
|
|
|
beyond the lifetime of a single Docker host. See the
|
2016-08-29 19:37:01 -04:00
|
|
|
[plugin documentation](legacy_plugins.md) for more information.
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2016-03-07 15:44:43 -05:00
|
|
|
## Changelog
|
|
|
|
|
2016-11-22 14:21:34 -05:00
|
|
|
### 1.13.0
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
- If used as part of the v2 plugin architecture, mountpoints that are part of
|
|
|
|
paths returned by the plugin must be mounted under the directory specified by
|
|
|
|
`PropagatedMount` in the plugin configuration
|
|
|
|
([#26398](https://github.com/docker/docker/pull/26398))
|
2016-11-22 14:21:34 -05:00
|
|
|
|
2016-03-07 15:44:43 -05:00
|
|
|
### 1.12.0
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
- Add `Status` field to `VolumeDriver.Get` response
|
|
|
|
([#21006](https://github.com/docker/docker/pull/21006#))
|
|
|
|
- Add `VolumeDriver.Capabilities` to get capabilities of the volume driver
|
|
|
|
([#22077](https://github.com/docker/docker/pull/22077))
|
2016-03-07 15:44:43 -05:00
|
|
|
|
|
|
|
### 1.10.0
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
- Add `VolumeDriver.Get` which gets the details about the volume
|
|
|
|
([#16534](https://github.com/docker/docker/pull/16534))
|
|
|
|
- Add `VolumeDriver.List` which lists all volumes owned by the driver
|
|
|
|
([#16534](https://github.com/docker/docker/pull/16534))
|
2016-03-07 15:44:43 -05:00
|
|
|
|
|
|
|
### 1.8.0
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
- Initial support for volume driver plugins
|
|
|
|
([#14659](https://github.com/docker/docker/pull/14659))
|
2016-03-07 15:44:43 -05:00
|
|
|
|
2016-01-04 09:42:03 -05:00
|
|
|
## Command-line changes
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
To give a container access to a volume, use the `--volume` and `--volume-driver`
|
|
|
|
flags on the `docker container run` command. The `--volume` (or `-v`) flag
|
|
|
|
accepts a volume name and path on the host, and the `--volume-driver` flag
|
|
|
|
accepts a driver type.
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
```bash
|
|
|
|
$ docker volume create --driver=flocker volumename
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
$ docker container run -it --volume volumename:/data busybox sh
|
|
|
|
```
|
|
|
|
|
|
|
|
### `--volume`
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
The `--volume` (or `-v`) flag takes a value that is in the format
|
|
|
|
`<volume_name>:<mountpoint>`. The two parts of the value are
|
|
|
|
separated by a colon (`:`) character.
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
- The volume name is a human-readable name for the volume, and cannot begin with
|
|
|
|
a `/` character. It is referred to as `volume_name` in the rest of this topic.
|
|
|
|
- The `Mountpoint` is the path on the host (v1) or in the plugin (v2) where the
|
|
|
|
volume has been made available.
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
### `volumedriver`
|
|
|
|
|
|
|
|
Specifying a `volumedriver` in conjunction with a `volumename` allows you to
|
|
|
|
use plugins such as [Flocker](https://github.com/ScatterHQ/flocker) to manage
|
|
|
|
volumes external to a single host, such as those on EBS.
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2016-01-04 09:42:03 -05:00
|
|
|
## Create a VolumeDriver
|
2015-05-22 19:47:28 -04:00
|
|
|
|
|
|
|
The container creation endpoint (`/containers/create`) accepts a `VolumeDriver`
|
2017-01-27 19:51:44 -05:00
|
|
|
field of type `string` allowing to specify the name of the driver. If not
|
|
|
|
specified, it defaults to `"local"` (the default driver for local volumes).
|
2015-05-22 19:47:28 -04:00
|
|
|
|
2016-01-04 09:42:03 -05:00
|
|
|
## Volume plugin protocol
|
2015-06-17 11:06:39 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
If a plugin registers itself as a `VolumeDriver` when activated, it must
|
|
|
|
provide the Docker Daemon with writeable paths on the host filesystem. The Docker
|
|
|
|
daemon provides these paths to containers to consume. The Docker daemon makes
|
|
|
|
the volumes available by bind-mounting the provided paths into the containers.
|
2015-06-17 11:06:39 -04:00
|
|
|
|
2016-01-04 09:42:03 -05:00
|
|
|
> **Note**: Volume plugins should *not* write data to the `/var/lib/docker/`
|
|
|
|
> directory, including `/var/lib/docker/volumes`. The `/var/lib/docker/`
|
|
|
|
> directory is reserved for Docker.
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
### `/VolumeDriver.Create`
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Request**:
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
2015-06-12 09:25:32 -04:00
|
|
|
"Name": "volume_name",
|
|
|
|
"Opts": {}
|
2015-06-17 11:06:39 -04:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Instruct the plugin that the user wants to create a volume, given a user
|
2017-01-27 19:51:44 -05:00
|
|
|
specified volume name. The plugin does not need to actually manifest the
|
|
|
|
volume on the filesystem yet (until `Mount` is called).
|
|
|
|
`Opts` is a map of driver specific options passed through from the user request.
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Response**:
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
2015-12-16 03:52:26 -05:00
|
|
|
"Err": ""
|
2015-06-17 11:06:39 -04:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Respond with a string error if an error occurred.
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
### `/VolumeDriver.Remove`
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Request**:
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
|
|
|
"Name": "volume_name"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
Delete the specified volume from disk. This request is issued when a user
|
|
|
|
invokes `docker rm -v` to remove volumes associated with a container.
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Response**:
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
2015-12-16 03:52:26 -05:00
|
|
|
"Err": ""
|
2015-06-17 11:06:39 -04:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Respond with a string error if an error occurred.
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
### `/VolumeDriver.Mount`
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Request**:
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
2016-03-07 21:41:44 -05:00
|
|
|
"Name": "volume_name",
|
|
|
|
"ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c"
|
2015-06-17 11:06:39 -04:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Docker requires the plugin to provide a volume, given a user specified volume
|
2017-01-27 19:51:44 -05:00
|
|
|
name. `Mount` is called once per container start. If the same `volume_name` is requested
|
2015-11-03 05:44:38 -05:00
|
|
|
more than once, the plugin may need to keep track of each new mount request and provision
|
|
|
|
at the first mount request and deprovision at the last corresponding unmount request.
|
2015-06-17 11:06:39 -04:00
|
|
|
|
2016-07-05 05:27:42 -04:00
|
|
|
`ID` is a unique ID for the caller that is requesting the mount.
|
2016-03-07 21:41:44 -05:00
|
|
|
|
2015-06-17 11:06:39 -04:00
|
|
|
**Response**:
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
- **v1**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Mountpoint": "/path/to/directory/on/host",
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- **v2**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Mountpoint": "/path/under/PropagatedMount",
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
`Mountpoint` is the path on the host (v1) or in the plugin (v2) where the volume
|
|
|
|
has been made available.
|
2015-06-17 11:06:39 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
`Err` is either empty or contains an error string.
|
|
|
|
|
|
|
|
### `/VolumeDriver.Path`
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Request**:
|
2017-01-27 19:51:44 -05:00
|
|
|
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
|
|
|
"Name": "volume_name"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
Request the path to the volume with the given `volume_name`.
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Response**:
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
- **v1**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Mountpoin": "/path/to/directory/on/host",
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- **v2**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Mountpoint": "/path/under/PropagatedMount",
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Respond with the path on the host (v1) or inside the plugin (v2) where the
|
|
|
|
volume has been made available, and/or a string error if an error occurred.
|
|
|
|
|
|
|
|
`Mountpoint` is optional. However, the plugin may be queried again later if one
|
|
|
|
is not provided.
|
2015-06-17 11:06:39 -04:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
### `/VolumeDriver.Unmount`
|
2015-06-17 11:06:39 -04:00
|
|
|
|
|
|
|
**Request**:
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
2016-03-07 21:41:44 -05:00
|
|
|
"Name": "volume_name",
|
|
|
|
"ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c"
|
2015-06-17 11:06:39 -04:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
Docker is no longer using the named volume. `Unmount` is called once per
|
|
|
|
container stop. Plugin may deduce that it is safe to deprovision the volume at
|
2015-06-17 11:06:39 -04:00
|
|
|
this point.
|
|
|
|
|
2016-07-05 05:27:42 -04:00
|
|
|
`ID` is a unique ID for the caller that is requesting the mount.
|
2016-03-07 21:41:44 -05:00
|
|
|
|
2015-06-17 11:06:39 -04:00
|
|
|
**Response**:
|
2016-01-05 21:07:34 -05:00
|
|
|
```json
|
2015-06-17 11:06:39 -04:00
|
|
|
{
|
2015-12-16 03:52:26 -05:00
|
|
|
"Err": ""
|
2015-06-17 11:06:39 -04:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Respond with a string error if an error occurred.
|
|
|
|
|
2016-01-05 21:07:34 -05:00
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
### `/VolumeDriver.Get`
|
2016-01-05 21:07:34 -05:00
|
|
|
|
|
|
|
**Request**:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Name": "volume_name"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-27 19:51:44 -05:00
|
|
|
Get info about `volume_name`.
|
2016-01-05 21:07:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
**Response**:
|
2017-01-27 19:51:44 -05:00
|
|
|
|
|
|
|
- **v1**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Volume": {
|
|
|
|
"Name": "volume_name",
|
|
|
|
"Mountpoint": "/path/to/directory/on/host",
|
|
|
|
"Status": {}
|
|
|
|
},
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- **v2**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Volume": {
|
|
|
|
"Name": "volume_name",
|
|
|
|
"Mountpoint": "/path/under/PropagatedMount",
|
|
|
|
"Status": {}
|
|
|
|
},
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
2016-01-05 21:07:34 -05:00
|
|
|
|
2016-06-12 16:33:03 -04:00
|
|
|
Respond with a string error if an error occurred. `Mountpoint` and `Status` are
|
|
|
|
optional.
|
2016-01-05 21:07:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
### /VolumeDriver.List
|
|
|
|
|
|
|
|
**Request**:
|
|
|
|
```json
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
Get the list of volumes registered with the plugin.
|
|
|
|
|
|
|
|
**Response**:
|
2017-01-27 19:51:44 -05:00
|
|
|
|
|
|
|
- **v1**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Volumes": [
|
|
|
|
{
|
|
|
|
"Name": "volume_name",
|
|
|
|
"Mountpoint": "/path/to/directory/on/host"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- **v2**:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Volumes": [
|
|
|
|
{
|
|
|
|
"Name": "volume_name",
|
|
|
|
"Mountpoint": "/path/under/PropagatedMount"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"Err": ""
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-01-05 21:07:34 -05:00
|
|
|
|
2016-06-12 16:33:03 -04:00
|
|
|
Respond with a string error if an error occurred. `Mountpoint` is optional.
|
2016-04-11 11:17:52 -04:00
|
|
|
|
|
|
|
### /VolumeDriver.Capabilities
|
|
|
|
|
|
|
|
**Request**:
|
|
|
|
```json
|
|
|
|
{}
|
|
|
|
```
|
|
|
|
|
|
|
|
Get the list of capabilities the driver supports.
|
2017-01-27 19:51:44 -05:00
|
|
|
|
|
|
|
The driver is not required to implement `Capabilities`. If it is not
|
|
|
|
implemented, the default values are used.
|
2016-04-11 11:17:52 -04:00
|
|
|
|
|
|
|
**Response**:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Capabilities": {
|
|
|
|
"Scope": "global"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Supported scopes are `global` and `local`. Any other value in `Scope` will be
|
2017-01-27 19:51:44 -05:00
|
|
|
ignored, and `local` is used. `Scope` allows cluster managers to handle the
|
|
|
|
volume in different ways. For instance, a scope of `global`, signals to the
|
|
|
|
cluster manager that it only needs to create the volume once instead of on each
|
|
|
|
Docker host. More capabilities may be added in the future.
|