github.com/boynux/docker@v1.11.0-rc4/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  ## Command-line changes
    19  
    20  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:
    21  
    22      $ docker run -ti -v volumename:/data --volume-driver=flocker   busybox sh
    23  
    24  This command passes the `volumename` through to the volume plugin as a
    25  user-given name for the volume. The `volumename` must not begin with a `/`.
    26  
    27  By having the user specify a  `volumename`, a plugin can associate the volume
    28  with an external volume beyond the lifetime of a single container or container
    29  host. This can be used, for example, to move a stateful container from one
    30  server to another.
    31  
    32  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.
    33  
    34  
    35  ## Create a VolumeDriver
    36  
    37  The container creation endpoint (`/containers/create`) accepts a `VolumeDriver`
    38  field of type `string` allowing to specify the name of the driver. It's default
    39  value of `"local"` (the default driver for local volumes).
    40  
    41  ## Volume plugin protocol
    42  
    43  If a plugin registers itself as a `VolumeDriver` when activated, then it is
    44  expected to provide writeable paths on the host filesystem for the Docker
    45  daemon to provide to containers to consume.
    46  
    47  The Docker daemon handles bind-mounting the provided paths into user
    48  containers.
    49  
    50  > **Note**: Volume plugins should *not* write data to the `/var/lib/docker/`
    51  > directory, including `/var/lib/docker/volumes`. The `/var/lib/docker/`
    52  > directory is reserved for Docker.
    53  
    54  ### /VolumeDriver.Create
    55  
    56  **Request**:
    57  ```json
    58  {
    59      "Name": "volume_name",
    60      "Opts": {}
    61  }
    62  ```
    63  
    64  Instruct the plugin that the user wants to create a volume, given a user
    65  specified volume name.  The plugin does not need to actually manifest the
    66  volume on the filesystem yet (until Mount is called).
    67  Opts is a map of driver specific options passed through from the user request.
    68  
    69  **Response**:
    70  ```json
    71  {
    72      "Err": ""
    73  }
    74  ```
    75  
    76  Respond with a string error if an error occurred.
    77  
    78  ### /VolumeDriver.Remove
    79  
    80  **Request**:
    81  ```json
    82  {
    83      "Name": "volume_name"
    84  }
    85  ```
    86  
    87  Delete the specified volume from disk. This request is issued when a user invokes `docker rm -v` to remove volumes associated with a container.
    88  
    89  **Response**:
    90  ```json
    91  {
    92      "Err": ""
    93  }
    94  ```
    95  
    96  Respond with a string error if an error occurred.
    97  
    98  ### /VolumeDriver.Mount
    99  
   100  **Request**:
   101  ```json
   102  {
   103      "Name": "volume_name"
   104  }
   105  ```
   106  
   107  Docker requires the plugin to provide a volume, given a user specified volume
   108  name. This is called once per container start. If the same volume_name is requested
   109  more than once, the plugin may need to keep track of each new mount request and provision
   110  at the first mount request and deprovision at the last corresponding unmount request.
   111  
   112  **Response**:
   113  ```json
   114  {
   115      "Mountpoint": "/path/to/directory/on/host",
   116      "Err": ""
   117  }
   118  ```
   119  
   120  Respond with the path on the host filesystem where the volume has been made
   121  available, and/or a string error if an error occurred.
   122  
   123  ### /VolumeDriver.Path
   124  
   125  **Request**:
   126  ```json
   127  {
   128      "Name": "volume_name"
   129  }
   130  ```
   131  
   132  Docker needs reminding of the path to the volume on the host.
   133  
   134  **Response**:
   135  ```json
   136  {
   137      "Mountpoint": "/path/to/directory/on/host",
   138      "Err": ""
   139  }
   140  ```
   141  
   142  Respond with the path on the host filesystem where the volume has been made
   143  available, and/or a string error if an error occurred.
   144  
   145  ### /VolumeDriver.Unmount
   146  
   147  **Request**:
   148  ```json
   149  {
   150      "Name": "volume_name"
   151  }
   152  ```
   153  
   154  Indication that Docker no longer is using the named volume. This is called once
   155  per container stop.  Plugin may deduce that it is safe to deprovision it at
   156  this point.
   157  
   158  **Response**:
   159  ```json
   160  {
   161      "Err": ""
   162  }
   163  ```
   164  
   165  Respond with a string error if an error occurred.
   166  
   167  
   168  ### /VolumeDriver.Get
   169  
   170  **Request**:
   171  ```json
   172  {
   173      "Name": "volume_name"
   174  }
   175  ```
   176  
   177  Get the volume info.
   178  
   179  
   180  **Response**:
   181  ```json
   182  {
   183    "Volume": {
   184      "Name": "volume_name",
   185      "Mountpoint": "/path/to/directory/on/host",
   186    },
   187    "Err": ""
   188  }
   189  ```
   190  
   191  Respond with a string error if an error occurred.
   192  
   193  
   194  ### /VolumeDriver.List
   195  
   196  **Request**:
   197  ```json
   198  {}
   199  ```
   200  
   201  Get the list of volumes registered with the plugin.
   202  
   203  **Response**:
   204  ```json
   205  {
   206    "Volumes": [
   207      {
   208        "Name": "volume_name",
   209        "Mountpoint": "/path/to/directory/on/host"
   210      }
   211    ],
   212    "Err": ""
   213  }
   214  ```
   215  
   216  Respond with a string error if an error occurred.