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