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