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