github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/extend/plugins_volume.md (about)

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