github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/docs/extend/plugins_volume.md (about) 1 --- 2 title: "Volume plugins" 3 description: "How to manage data with external volume plugins" 4 keywords: "Examples, Usage, volume, docker, data, volumes, plugin, api" 5 --- 6 7 <!-- This file is maintained within the docker/docker Github 8 repository at https://github.com/docker/docker/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # Write a volume plugin 17 18 Docker Engine volume plugins enable Engine deployments to be integrated with 19 external storage systems, such as Amazon EBS, and enable data volumes to persist 20 beyond the lifetime of a single Engine host. See the 21 [plugin documentation](legacy_plugins.md) for more information. 22 23 ## Changelog 24 25 ### 1.13.0 26 27 - If used as part of the v2 plugin architecture, mountpoints that are part of paths returned by plugin have to be mounted under the directory specified by PropagatedMount in the plugin configuration [#26398](https://github.com/docker/docker/pull/26398) 28 29 ### 1.12.0 30 31 - Add `Status` field to `VolumeDriver.Get` response ([#21006](https://github.com/docker/docker/pull/21006#)) 32 - Add `VolumeDriver.Capabilities` to get capabilities of the volume driver([#22077](https://github.com/docker/docker/pull/22077)) 33 34 ### 1.10.0 35 36 - Add `VolumeDriver.Get` which gets the details about the volume ([#16534](https://github.com/docker/docker/pull/16534)) 37 - Add `VolumeDriver.List` which lists all volumes owned by the driver ([#16534](https://github.com/docker/docker/pull/16534)) 38 39 ### 1.8.0 40 41 - Initial support for volume driver plugins ([#14659](https://github.com/docker/docker/pull/14659)) 42 43 ## Command-line changes 44 45 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: 46 47 $ docker run -ti -v volumename:/data --volume-driver=flocker busybox sh 48 49 This command passes the `volumename` through to the volume plugin as a 50 user-given name for the volume. The `volumename` must not begin with a `/`. 51 52 By having the user specify a `volumename`, a plugin can associate the volume 53 with an external volume beyond the lifetime of a single container or container 54 host. This can be used, for example, to move a stateful container from one 55 server to another. 56 57 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. 58 59 60 ## Create a VolumeDriver 61 62 The container creation endpoint (`/containers/create`) accepts a `VolumeDriver` 63 field of type `string` allowing to specify the name of the driver. It's default 64 value of `"local"` (the default driver for local volumes). 65 66 ## Volume plugin protocol 67 68 If a plugin registers itself as a `VolumeDriver` when activated, then it is 69 expected to provide writeable paths on the host filesystem for the Docker 70 daemon to provide to containers to consume. 71 72 The Docker daemon handles bind-mounting the provided paths into user 73 containers. 74 75 > **Note**: Volume plugins should *not* write data to the `/var/lib/docker/` 76 > directory, including `/var/lib/docker/volumes`. The `/var/lib/docker/` 77 > directory is reserved for Docker. 78 79 ### /VolumeDriver.Create 80 81 **Request**: 82 ```json 83 { 84 "Name": "volume_name", 85 "Opts": {} 86 } 87 ``` 88 89 Instruct the plugin that the user wants to create a volume, given a user 90 specified volume name. The plugin does not need to actually manifest the 91 volume on the filesystem yet (until Mount is called). 92 Opts is a map of driver specific options passed through from the user request. 93 94 **Response**: 95 ```json 96 { 97 "Err": "" 98 } 99 ``` 100 101 Respond with a string error if an error occurred. 102 103 ### /VolumeDriver.Remove 104 105 **Request**: 106 ```json 107 { 108 "Name": "volume_name" 109 } 110 ``` 111 112 Delete the specified volume from disk. This request is issued when a user invokes `docker rm -v` to remove volumes associated with a container. 113 114 **Response**: 115 ```json 116 { 117 "Err": "" 118 } 119 ``` 120 121 Respond with a string error if an error occurred. 122 123 ### /VolumeDriver.Mount 124 125 **Request**: 126 ```json 127 { 128 "Name": "volume_name", 129 "ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c" 130 } 131 ``` 132 133 Docker requires the plugin to provide a volume, given a user specified volume 134 name. This is called once per container start. If the same volume_name is requested 135 more than once, the plugin may need to keep track of each new mount request and provision 136 at the first mount request and deprovision at the last corresponding unmount request. 137 138 `ID` is a unique ID for the caller that is requesting the mount. 139 140 **Response**: 141 ```json 142 { 143 "Mountpoint": "/path/to/directory/on/host", 144 "Err": "" 145 } 146 ``` 147 148 Respond with the path on the host filesystem where the volume has been made 149 available, and/or a string error if an error occurred. 150 151 ### /VolumeDriver.Path 152 153 **Request**: 154 ```json 155 { 156 "Name": "volume_name" 157 } 158 ``` 159 160 Docker needs reminding of the path to the volume on the host. 161 162 **Response**: 163 ```json 164 { 165 "Mountpoint": "/path/to/directory/on/host", 166 "Err": "" 167 } 168 ``` 169 170 Respond with the path on the host filesystem where the volume has been made 171 available, and/or a string error if an error occurred. `Mountpoint` is optional, 172 however, the plugin may be queried again later if one is not provided. 173 174 ### /VolumeDriver.Unmount 175 176 **Request**: 177 ```json 178 { 179 "Name": "volume_name", 180 "ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c" 181 } 182 ``` 183 184 Indication that Docker no longer is using the named volume. This is called once 185 per container stop. Plugin may deduce that it is safe to deprovision it at 186 this point. 187 188 `ID` is a unique ID for the caller that is requesting the mount. 189 190 **Response**: 191 ```json 192 { 193 "Err": "" 194 } 195 ``` 196 197 Respond with a string error if an error occurred. 198 199 200 ### /VolumeDriver.Get 201 202 **Request**: 203 ```json 204 { 205 "Name": "volume_name" 206 } 207 ``` 208 209 Get the volume info. 210 211 212 **Response**: 213 ```json 214 { 215 "Volume": { 216 "Name": "volume_name", 217 "Mountpoint": "/path/to/directory/on/host", 218 "Status": {} 219 }, 220 "Err": "" 221 } 222 ``` 223 224 Respond with a string error if an error occurred. `Mountpoint` and `Status` are 225 optional. 226 227 228 ### /VolumeDriver.List 229 230 **Request**: 231 ```json 232 {} 233 ``` 234 235 Get the list of volumes registered with the plugin. 236 237 **Response**: 238 ```json 239 { 240 "Volumes": [ 241 { 242 "Name": "volume_name", 243 "Mountpoint": "/path/to/directory/on/host" 244 } 245 ], 246 "Err": "" 247 } 248 ``` 249 250 Respond with a string error if an error occurred. `Mountpoint` is optional. 251 252 ### /VolumeDriver.Capabilities 253 254 **Request**: 255 ```json 256 {} 257 ``` 258 259 Get the list of capabilities the driver supports. 260 The driver is not required to implement this endpoint, however, in such cases 261 the default values will be taken. 262 263 **Response**: 264 ```json 265 { 266 "Capabilities": { 267 "Scope": "global" 268 } 269 } 270 ``` 271 272 Supported scopes are `global` and `local`. Any other value in `Scope` will be 273 ignored and assumed to be `local`. Scope allows cluster managers to handle the 274 volume differently, for instance with a scope of `global`, the cluster manager 275 knows it only needs to create the volume once instead of on every engine. More 276 capabilities may be added in the future.