2015-07-15 14:25:56 -04:00
<!-- [metadata]>
+++
title = "Volume plugins"
description = "How to manage data with external volume plugins"
keywords = ["Examples, Usage, volume, docker, data, volumes, plugin, api"]
[menu.main]
2016-01-23 23:36:40 -05:00
parent = "engine_extend"
2015-07-15 14:25:56 -04:00
+++
<![end-metadata]-->
# 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
external storage systems, such as Amazon EBS, and enable data volumes to persist
beyond the lifetime of a single Engine host. See the [plugin
documentation](plugins.md) for more information.
2015-05-22 19:47:28 -04:00
2016-03-07 15:44:43 -05:00
## Changelog
### 1.12.0
- Add `Status` field to `VolumeDriver.Get` response ([#21006](https://github.com/docker/docker/pull/21006#))
2016-04-11 11:17:52 -04:00
- 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
- 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))
### 1.8.0
- Initial support for volume driver plugins ([#14659](https://github.com/docker/docker/pull/14659))
2016-01-04 09:42:03 -05:00
## Command-line changes
2015-05-22 19:47:28 -04:00
2016-01-23 23:36:40 -05:00
A volume plugin makes use of the `-v` and `--volume-driver` flag on the `docker run` command. The `-v` flag accepts a volume name and the `--volume-driver` flag a driver type, for example:
2015-05-22 19:47:28 -04:00
2015-07-15 14:25:56 -04:00
$ docker run -ti -v volumename:/data --volume-driver=flocker busybox sh
2015-05-22 19:47:28 -04:00
2015-07-15 14:25:56 -04:00
This command passes the `volumename` through to the volume plugin as a
2016-01-23 23:36:40 -05:00
user-given name for the volume. The `volumename` must not begin with a `/` .
2015-05-22 19:47:28 -04:00
2015-07-15 14:25:56 -04:00
By having the user specify a `volumename` , a plugin can associate the volume
with an external volume beyond the lifetime of a single container or container
host. This can be used, for example, to move a stateful container from one
server to another.
2015-05-22 19:47:28 -04:00
2016-01-23 23:36:40 -05:00
By specifying a `volumedriver` in conjunction with a `volumename` , users can use plugins such as [Flocker ](https://clusterhq.com/docker-plugin/ ) 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`
field of type `string` allowing to specify the name of the driver. It's default
value of `"local"` (the default driver for local volumes).
2016-01-04 09:42:03 -05:00
## Volume plugin protocol
2015-06-17 11:06:39 -04:00
If a plugin registers itself as a `VolumeDriver` when activated, then it is
expected to provide writeable paths on the host filesystem for the Docker
daemon to provide to containers to consume.
The Docker daemon handles bind-mounting the provided paths into user
containers.
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.
2015-06-17 11:06:39 -04:00
### /VolumeDriver.Create
**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
specified volume name. The plugin does not need to actually manifest the
volume on the filesystem yet (until Mount is called).
2015-06-12 09:25:32 -04:00
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.
### /VolumeDriver.Remove
**Request**:
2016-01-05 21:07:34 -05:00
```json
2015-06-17 11:06:39 -04:00
{
"Name": "volume_name"
}
```
2015-07-11 15:35:14 -04: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.
### /VolumeDriver.Mount
**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
2015-11-03 05:44:38 -05:00
name. This is called once per container start. If the same volume_name is requested
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**:
2016-01-05 21:07:34 -05:00
```json
2015-06-17 11:06:39 -04:00
{
"Mountpoint": "/path/to/directory/on/host",
2015-12-16 03:52:26 -05:00
"Err": ""
2015-06-17 11:06:39 -04:00
}
```
Respond with the path on the host filesystem where the volume has been made
available, and/or a string error if an error occurred.
### /VolumeDriver.Path
**Request**:
2016-01-05 21:07:34 -05:00
```json
2015-06-17 11:06:39 -04:00
{
"Name": "volume_name"
}
```
Docker needs reminding of the path to the volume on the host.
**Response**:
2016-01-05 21:07:34 -05:00
```json
2015-06-17 11:06:39 -04:00
{
"Mountpoint": "/path/to/directory/on/host",
2015-12-16 03:52:26 -05:00
"Err": ""
2015-06-17 11:06:39 -04:00
}
```
Respond with the path on the host filesystem where the volume has been made
2016-06-12 16:33:03 -04:00
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
### /VolumeDriver.Unmount
**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
}
```
Indication that Docker no longer is using the named volume. This is called once
per container stop. Plugin may deduce that it is safe to deprovision it at
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
### /VolumeDriver.Get
**Request**:
```json
{
"Name": "volume_name"
}
```
Get the volume info.
**Response**:
```json
{
"Volume": {
"Name": "volume_name",
"Mountpoint": "/path/to/directory/on/host",
2016-03-07 15:44:43 -05:00
"Status": {}
2016-01-05 21:07:34 -05:00
},
"Err": ""
}
```
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**:
```json
{
"Volumes": [
{
"Name": "volume_name",
"Mountpoint": "/path/to/directory/on/host"
}
],
"Err": ""
}
```
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.
The driver is not required to implement this endpoint, however in such cases
the default values will be taken.
**Response**:
```json
{
"Capabilities": {
"Scope": "global"
}
}
```
Supported scopes are `global` and `local` . Any other value in `Scope` will be
ignored and assumed to be `local` . Scope allows cluster managers to handle the
volume differently, for instance with a scope of `global` , the cluster manager
knows it only needs to create the volume once instead of on every engine. More
capabilities may be added in the future.