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