github.com/sld880311/docker@v0.0.0-20200524143708-d5593973a475/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 Docker 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 28 paths returned by the plugin must be mounted under the directory specified by 29 `PropagatedMount` in the plugin configuration 30 ([#26398](https://github.com/docker/docker/pull/26398)) 31 32 ### 1.12.0 33 34 - Add `Status` field to `VolumeDriver.Get` response 35 ([#21006](https://github.com/docker/docker/pull/21006#)) 36 - Add `VolumeDriver.Capabilities` to get capabilities of the volume driver 37 ([#22077](https://github.com/docker/docker/pull/22077)) 38 39 ### 1.10.0 40 41 - Add `VolumeDriver.Get` which gets the details about the volume 42 ([#16534](https://github.com/docker/docker/pull/16534)) 43 - Add `VolumeDriver.List` which lists all volumes owned by the driver 44 ([#16534](https://github.com/docker/docker/pull/16534)) 45 46 ### 1.8.0 47 48 - Initial support for volume driver plugins 49 ([#14659](https://github.com/docker/docker/pull/14659)) 50 51 ## Command-line changes 52 53 To give a container access to a volume, use the `--volume` and `--volume-driver` 54 flags on the `docker container run` command. The `--volume` (or `-v`) flag 55 accepts a volume name and path on the host, and the `--volume-driver` flag 56 accepts a driver type. 57 58 ```bash 59 $ docker volume create --driver=flocker volumename 60 61 $ docker container run -it --volume volumename:/data busybox sh 62 ``` 63 64 ### `--volume` 65 66 The `--volume` (or `-v`) flag takes a value that is in the format 67 `<volume_name>:<mountpoint>`. The two parts of the value are 68 separated by a colon (`:`) character. 69 70 - The volume name is a human-readable name for the volume, and cannot begin with 71 a `/` character. It is referred to as `volume_name` in the rest of this topic. 72 - The `Mountpoint` is the path on the host (v1) or in the plugin (v2) where the 73 volume has been made available. 74 75 ### `volumedriver` 76 77 Specifying a `volumedriver` in conjunction with a `volumename` allows you to 78 use plugins such as [Flocker](https://github.com/ScatterHQ/flocker) to manage 79 volumes external to a single host, such as those on EBS. 80 81 ## Create a VolumeDriver 82 83 The container creation endpoint (`/containers/create`) accepts a `VolumeDriver` 84 field of type `string` allowing to specify the name of the driver. If not 85 specified, it defaults to `"local"` (the default driver for local volumes). 86 87 ## Volume plugin protocol 88 89 If a plugin registers itself as a `VolumeDriver` when activated, it must 90 provide the Docker Daemon with writeable paths on the host filesystem. The Docker 91 daemon provides these paths to containers to consume. The Docker daemon makes 92 the volumes available by bind-mounting the provided paths into the containers. 93 94 > **Note**: Volume plugins should *not* write data to the `/var/lib/docker/` 95 > directory, including `/var/lib/docker/volumes`. The `/var/lib/docker/` 96 > directory is reserved for Docker. 97 98 ### `/VolumeDriver.Create` 99 100 **Request**: 101 ```json 102 { 103 "Name": "volume_name", 104 "Opts": {} 105 } 106 ``` 107 108 Instruct the plugin that the user wants to create a volume, given a user 109 specified volume name. The plugin does not need to actually manifest the 110 volume on the filesystem yet (until `Mount` is called). 111 `Opts` is a map of driver specific options passed through from the user request. 112 113 **Response**: 114 ```json 115 { 116 "Err": "" 117 } 118 ``` 119 120 Respond with a string error if an error occurred. 121 122 ### `/VolumeDriver.Remove` 123 124 **Request**: 125 ```json 126 { 127 "Name": "volume_name" 128 } 129 ``` 130 131 Delete the specified volume from disk. This request is issued when a user 132 invokes `docker rm -v` to remove volumes associated with a container. 133 134 **Response**: 135 ```json 136 { 137 "Err": "" 138 } 139 ``` 140 141 Respond with a string error if an error occurred. 142 143 ### `/VolumeDriver.Mount` 144 145 **Request**: 146 ```json 147 { 148 "Name": "volume_name", 149 "ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c" 150 } 151 ``` 152 153 Docker requires the plugin to provide a volume, given a user specified volume 154 name. `Mount` is called once per container start. If the same `volume_name` is requested 155 more than once, the plugin may need to keep track of each new mount request and provision 156 at the first mount request and deprovision at the last corresponding unmount request. 157 158 `ID` is a unique ID for the caller that is requesting the mount. 159 160 **Response**: 161 162 - **v1**: 163 164 ```json 165 { 166 "Mountpoint": "/path/to/directory/on/host", 167 "Err": "" 168 } 169 ``` 170 171 - **v2**: 172 173 ```json 174 { 175 "Mountpoint": "/path/under/PropagatedMount", 176 "Err": "" 177 } 178 ``` 179 180 `Mountpoint` is the path on the host (v1) or in the plugin (v2) where the volume 181 has been made available. 182 183 `Err` is either empty or contains an error string. 184 185 ### `/VolumeDriver.Path` 186 187 **Request**: 188 189 ```json 190 { 191 "Name": "volume_name" 192 } 193 ``` 194 195 Request the path to the volume with the given `volume_name`. 196 197 **Response**: 198 199 - **v1**: 200 201 ```json 202 { 203 "Mountpoin": "/path/to/directory/on/host", 204 "Err": "" 205 } 206 ``` 207 208 - **v2**: 209 210 ```json 211 { 212 "Mountpoint": "/path/under/PropagatedMount", 213 "Err": "" 214 } 215 ``` 216 217 Respond with the path on the host (v1) or inside the plugin (v2) where the 218 volume has been made available, and/or a string error if an error occurred. 219 220 `Mountpoint` is optional. However, the plugin may be queried again later if one 221 is not provided. 222 223 ### `/VolumeDriver.Unmount` 224 225 **Request**: 226 ```json 227 { 228 "Name": "volume_name", 229 "ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c" 230 } 231 ``` 232 233 Docker is no longer using the named volume. `Unmount` is called once per 234 container stop. Plugin may deduce that it is safe to deprovision the volume at 235 this point. 236 237 `ID` is a unique ID for the caller that is requesting the mount. 238 239 **Response**: 240 ```json 241 { 242 "Err": "" 243 } 244 ``` 245 246 Respond with a string error if an error occurred. 247 248 249 ### `/VolumeDriver.Get` 250 251 **Request**: 252 ```json 253 { 254 "Name": "volume_name" 255 } 256 ``` 257 258 Get info about `volume_name`. 259 260 261 **Response**: 262 263 - **v1**: 264 265 ```json 266 { 267 "Volume": { 268 "Name": "volume_name", 269 "Mountpoint": "/path/to/directory/on/host", 270 "Status": {} 271 }, 272 "Err": "" 273 } 274 ``` 275 276 - **v2**: 277 278 ```json 279 { 280 "Volume": { 281 "Name": "volume_name", 282 "Mountpoint": "/path/under/PropagatedMount", 283 "Status": {} 284 }, 285 "Err": "" 286 } 287 ``` 288 289 Respond with a string error if an error occurred. `Mountpoint` and `Status` are 290 optional. 291 292 293 ### /VolumeDriver.List 294 295 **Request**: 296 ```json 297 {} 298 ``` 299 300 Get the list of volumes registered with the plugin. 301 302 **Response**: 303 304 - **v1**: 305 306 ```json 307 { 308 "Volumes": [ 309 { 310 "Name": "volume_name", 311 "Mountpoint": "/path/to/directory/on/host" 312 } 313 ], 314 "Err": "" 315 } 316 ``` 317 318 - **v2**: 319 320 ```json 321 { 322 "Volumes": [ 323 { 324 "Name": "volume_name", 325 "Mountpoint": "/path/under/PropagatedMount" 326 } 327 ], 328 "Err": "" 329 } 330 ``` 331 332 333 Respond with a string error if an error occurred. `Mountpoint` is optional. 334 335 ### /VolumeDriver.Capabilities 336 337 **Request**: 338 ```json 339 {} 340 ``` 341 342 Get the list of capabilities the driver supports. 343 344 The driver is not required to implement `Capabilities`. If it is not 345 implemented, the default values are used. 346 347 **Response**: 348 ```json 349 { 350 "Capabilities": { 351 "Scope": "global" 352 } 353 } 354 ``` 355 356 Supported scopes are `global` and `local`. Any other value in `Scope` will be 357 ignored, and `local` is used. `Scope` allows cluster managers to handle the 358 volume in different ways. For instance, a scope of `global`, signals to the 359 cluster manager that it only needs to create the volume once instead of on each 360 Docker host. More capabilities may be added in the future.