github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/docs/content/docker.md (about) 1 --- 2 title: "Docker Volume Plugin" 3 description: "Docker Volume Plugin" 4 versionIntroduced: "v1.56" 5 --- 6 7 # Docker Volume Plugin 8 9 ## Introduction 10 11 Docker 1.9 has added support for creating 12 [named volumes](https://docs.docker.com/storage/volumes/) via 13 [command-line interface](https://docs.docker.com/engine/reference/commandline/volume_create/) 14 and mounting them in containers as a way to share data between them. 15 Since Docker 1.10 you can create named volumes with 16 [Docker Compose](https://docs.docker.com/compose/) by descriptions in 17 [docker-compose.yml](https://docs.docker.com/compose/compose-file/compose-file-v2/#volume-configuration-reference) 18 files for use by container groups on a single host. 19 As of Docker 1.12 volumes are supported by 20 [Docker Swarm](https://docs.docker.com/engine/swarm/key-concepts/) 21 included with Docker Engine and created from descriptions in 22 [swarm compose v3](https://docs.docker.com/compose/compose-file/compose-file-v3/#volume-configuration-reference) 23 files for use with _swarm stacks_ across multiple cluster nodes. 24 25 [Docker Volume Plugins](https://docs.docker.com/engine/extend/plugins_volume/) 26 augment the default `local` volume driver included in Docker with stateful 27 volumes shared across containers and hosts. Unlike local volumes, your 28 data will _not_ be deleted when such volume is removed. Plugins can run 29 managed by the docker daemon, as a native system service 30 (under systemd, _sysv_ or _upstart_) or as a standalone executable. 31 Rclone can run as docker volume plugin in all these modes. 32 It interacts with the local docker daemon 33 via [plugin API](https://docs.docker.com/engine/extend/plugin_api/) and 34 handles mounting of remote file systems into docker containers so it must 35 run on the same host as the docker daemon or on every Swarm node. 36 37 ## Getting started 38 39 In the first example we will use the [SFTP](/sftp/) 40 rclone volume with Docker engine on a standalone Ubuntu machine. 41 42 Start from [installing Docker](https://docs.docker.com/engine/install/) 43 on the host. 44 45 The _FUSE_ driver is a prerequisite for rclone mounting and should be 46 installed on host: 47 ``` 48 sudo apt-get -y install fuse 49 ``` 50 51 Create two directories required by rclone docker plugin: 52 ``` 53 sudo mkdir -p /var/lib/docker-plugins/rclone/config 54 sudo mkdir -p /var/lib/docker-plugins/rclone/cache 55 ``` 56 57 Install the managed rclone docker plugin for your architecture (here `amd64`): 58 ``` 59 docker plugin install rclone/docker-volume-rclone:amd64 args="-v" --alias rclone --grant-all-permissions 60 docker plugin list 61 ``` 62 63 Create your [SFTP volume](/sftp/#standard-options): 64 ``` 65 docker volume create firstvolume -d rclone -o type=sftp -o sftp-host=_hostname_ -o sftp-user=_username_ -o sftp-pass=_password_ -o allow-other=true 66 ``` 67 68 Note that since all options are static, you don't even have to run 69 `rclone config` or create the `rclone.conf` file (but the `config` directory 70 should still be present). In the simplest case you can use `localhost` 71 as _hostname_ and your SSH credentials as _username_ and _password_. 72 You can also change the remote path to your home directory on the host, 73 for example `-o path=/home/username`. 74 75 76 Time to create a test container and mount the volume into it: 77 ``` 78 docker run --rm -it -v firstvolume:/mnt --workdir /mnt ubuntu:latest bash 79 ``` 80 81 If all goes well, you will enter the new container and change right to 82 the mounted SFTP remote. You can type `ls` to list the mounted directory 83 or otherwise play with it. Type `exit` when you are done. 84 The container will stop but the volume will stay, ready to be reused. 85 When it's not needed anymore, remove it: 86 ``` 87 docker volume list 88 docker volume remove firstvolume 89 ``` 90 91 Now let us try **something more elaborate**: 92 [Google Drive](/drive/) volume on multi-node Docker Swarm. 93 94 You should start from installing Docker and FUSE, creating plugin 95 directories and installing rclone plugin on _every_ swarm node. 96 Then [setup the Swarm](https://docs.docker.com/engine/swarm/swarm-mode/). 97 98 Google Drive volumes need an access token which can be setup via web 99 browser and will be periodically renewed by rclone. The managed 100 plugin cannot run a browser so we will use a technique similar to the 101 [rclone setup on a headless box](/remote_setup/). 102 103 Run [rclone config](/commands/rclone_config_create/) 104 on _another_ machine equipped with _web browser_ and graphical user interface. 105 Create the [Google Drive remote](/drive/#standard-options). 106 When done, transfer the resulting `rclone.conf` to the Swarm cluster 107 and save as `/var/lib/docker-plugins/rclone/config/rclone.conf` 108 on _every_ node. By default this location is accessible only to the 109 root user so you will need appropriate privileges. The resulting config 110 will look like this: 111 ``` 112 [gdrive] 113 type = drive 114 scope = drive 115 drive_id = 1234567... 116 root_folder_id = 0Abcd... 117 token = {"access_token":...} 118 ``` 119 120 Now create the file named `example.yml` with a swarm stack description 121 like this: 122 ``` 123 version: '3' 124 services: 125 heimdall: 126 image: linuxserver/heimdall:latest 127 ports: [8080:80] 128 volumes: [configdata:/config] 129 volumes: 130 configdata: 131 driver: rclone 132 driver_opts: 133 remote: 'gdrive:heimdall' 134 allow_other: 'true' 135 vfs_cache_mode: full 136 poll_interval: 0 137 ``` 138 139 and run the stack: 140 ``` 141 docker stack deploy example -c ./example.yml 142 ``` 143 144 After a few seconds docker will spread the parsed stack description 145 over cluster, create the `example_heimdall` service on port _8080_, 146 run service containers on one or more cluster nodes and request 147 the `example_configdata` volume from rclone plugins on the node hosts. 148 You can use the following commands to confirm results: 149 ``` 150 docker service ls 151 docker service ps example_heimdall 152 docker volume ls 153 ``` 154 155 Point your browser to `http://cluster.host.address:8080` and play with 156 the service. Stop it with `docker stack remove example` when you are done. 157 Note that the `example_configdata` volume(s) created on demand at the 158 cluster nodes will not be automatically removed together with the stack 159 but stay for future reuse. You can remove them manually by invoking 160 the `docker volume remove example_configdata` command on every node. 161 162 ## Creating Volumes via CLI 163 164 Volumes can be created with [docker volume create](https://docs.docker.com/engine/reference/commandline/volume_create/). 165 Here are a few examples: 166 ``` 167 docker volume create vol1 -d rclone -o remote=storj: -o vfs-cache-mode=full 168 docker volume create vol2 -d rclone -o remote=:storj,access_grant=xxx:heimdall 169 docker volume create vol3 -d rclone -o type=storj -o path=heimdall -o storj-access-grant=xxx -o poll-interval=0 170 ``` 171 172 Note the `-d rclone` flag that tells docker to request volume from the 173 rclone driver. This works even if you installed managed driver by its full 174 name `rclone/docker-volume-rclone` because you provided the `--alias rclone` 175 option. 176 177 Volumes can be inspected as follows: 178 ``` 179 docker volume list 180 docker volume inspect vol1 181 ``` 182 183 ## Volume Configuration 184 185 Rclone flags and volume options are set via the `-o` flag to the 186 `docker volume create` command. They include backend-specific parameters 187 as well as mount and _VFS_ options. Also there are a few 188 special `-o` options: 189 `remote`, `fs`, `type`, `path`, `mount-type` and `persist`. 190 191 `remote` determines an existing remote name from the config file, with 192 trailing colon and optionally with a remote path. See the full syntax in 193 the [rclone documentation](/docs/#syntax-of-remote-paths). 194 This option can be aliased as `fs` to prevent confusion with the 195 _remote_ parameter of such backends as _crypt_ or _alias_. 196 197 The `remote=:backend:dir/subdir` syntax can be used to create 198 [on-the-fly (config-less) remotes](/docs/#backend-path-to-dir), 199 while the `type` and `path` options provide a simpler alternative for this. 200 Using two split options 201 ``` 202 -o type=backend -o path=dir/subdir 203 ``` 204 is equivalent to the combined syntax 205 ``` 206 -o remote=:backend:dir/subdir 207 ``` 208 but is arguably easier to parameterize in scripts. 209 The `path` part is optional. 210 211 [Mount and VFS options](/commands/rclone_serve_docker/#options) 212 as well as [backend parameters](/flags/#backend-flags) are named 213 like their twin command-line flags without the `--` CLI prefix. 214 Optionally you can use underscores instead of dashes in option names. 215 For example, `--vfs-cache-mode full` becomes 216 `-o vfs-cache-mode=full` or `-o vfs_cache_mode=full`. 217 Boolean CLI flags without value will gain the `true` value, e.g. 218 `--allow-other` becomes `-o allow-other=true` or `-o allow_other=true`. 219 220 Please note that you can provide parameters only for the backend immediately 221 referenced by the backend type of mounted `remote`. 222 If this is a wrapping backend like _alias, chunker or crypt_, you cannot 223 provide options for the referred to remote or backend. This limitation is 224 imposed by the rclone connection string parser. The only workaround is to 225 feed plugin with `rclone.conf` or configure plugin arguments (see below). 226 227 ## Special Volume Options 228 229 `mount-type` determines the mount method and in general can be one of: 230 `mount`, `cmount`, or `mount2`. This can be aliased as `mount_type`. 231 It should be noted that the managed rclone docker plugin currently does 232 not support the `cmount` method and `mount2` is rarely needed. 233 This option defaults to the first found method, which is usually `mount` 234 so you generally won't need it. 235 236 `persist` is a reserved boolean (true/false) option. 237 In future it will allow to persist on-the-fly remotes in the plugin 238 `rclone.conf` file. 239 240 ## Connection Strings 241 242 The `remote` value can be extended 243 with [connection strings](/docs/#connection-strings) 244 as an alternative way to supply backend parameters. This is equivalent 245 to the `-o` backend options with one _syntactic difference_. 246 Inside connection string the backend prefix must be dropped from parameter 247 names but in the `-o param=value` array it must be present. 248 For instance, compare the following option array 249 ``` 250 -o remote=:sftp:/home -o sftp-host=localhost 251 ``` 252 with equivalent connection string: 253 ``` 254 -o remote=:sftp,host=localhost:/home 255 ``` 256 This difference exists because flag options `-o key=val` include not only 257 backend parameters but also mount/VFS flags and possibly other settings. 258 Also it allows to discriminate the `remote` option from the `crypt-remote` 259 (or similarly named backend parameters) and arguably simplifies scripting 260 due to clearer value substitution. 261 262 ## Using with Swarm or Compose 263 264 Both _Docker Swarm_ and _Docker Compose_ use 265 [YAML](http://yaml.org/spec/1.2/spec.html)-formatted text files to describe 266 groups (stacks) of containers, their properties, networks and volumes. 267 _Compose_ uses the [compose v2](https://docs.docker.com/compose/compose-file/compose-file-v2/#volume-configuration-reference) format, 268 _Swarm_ uses the [compose v3](https://docs.docker.com/compose/compose-file/compose-file-v3/#volume-configuration-reference) format. 269 They are mostly similar, differences are explained in the 270 [docker documentation](https://docs.docker.com/compose/compose-file/compose-versioning/#upgrading). 271 272 Volumes are described by the children of the top-level `volumes:` node. 273 Each of them should be named after its volume and have at least two 274 elements, the self-explanatory `driver: rclone` value and the 275 `driver_opts:` structure playing the same role as `-o key=val` CLI flags: 276 277 ``` 278 volumes: 279 volume_name_1: 280 driver: rclone 281 driver_opts: 282 remote: 'gdrive:' 283 allow_other: 'true' 284 vfs_cache_mode: full 285 token: '{"type": "borrower", "expires": "2021-12-31"}' 286 poll_interval: 0 287 ``` 288 289 Notice a few important details: 290 - YAML prefers `_` in option names instead of `-`. 291 - YAML treats single and double quotes interchangeably. 292 Simple strings and integers can be left unquoted. 293 - Boolean values must be quoted like `'true'` or `"false"` because 294 these two words are reserved by YAML. 295 - The filesystem string is keyed with `remote` (or with `fs`). 296 Normally you can omit quotes here, but if the string ends with colon, 297 you **must** quote it like `remote: "storage_box:"`. 298 - YAML is picky about surrounding braces in values as this is in fact 299 another [syntax for key/value mappings](http://yaml.org/spec/1.2/spec.html#id2790832). 300 For example, JSON access tokens usually contain double quotes and 301 surrounding braces, so you must put them in single quotes. 302 303 ## Installing as Managed Plugin 304 305 Docker daemon can install plugins from an image registry and run them managed. 306 We maintain the 307 [docker-volume-rclone](https://hub.docker.com/p/rclone/docker-volume-rclone/) 308 plugin image on [Docker Hub](https://hub.docker.com). 309 310 Rclone volume plugin requires **Docker Engine >= 19.03.15** 311 312 The plugin requires presence of two directories on the host before it can 313 be installed. Note that plugin will **not** create them automatically. 314 By default they must exist on host at the following locations 315 (though you can tweak the paths): 316 - `/var/lib/docker-plugins/rclone/config` 317 is reserved for the `rclone.conf` config file and **must** exist 318 even if it's empty and the config file is not present. 319 - `/var/lib/docker-plugins/rclone/cache` 320 holds the plugin state file as well as optional VFS caches. 321 322 You can [install managed plugin](https://docs.docker.com/engine/reference/commandline/plugin_install/) 323 with default settings as follows: 324 ``` 325 docker plugin install rclone/docker-volume-rclone:amd64 --grant-all-permissions --alias rclone 326 ``` 327 328 The `:amd64` part of the image specification after colon is called a _tag_. 329 Usually you will want to install the latest plugin for your architecture. In 330 this case the tag will just name it, like `amd64` above. The following plugin 331 architectures are currently available: 332 - `amd64` 333 - `arm64` 334 - `arm-v7` 335 336 Sometimes you might want a concrete plugin version, not the latest one. 337 Then you should use image tag in the form `:ARCHITECTURE-VERSION`. 338 For example, to install plugin version `v1.56.2` on architecture `arm64` 339 you will use tag `arm64-1.56.2` (note the removed `v`) so the full image 340 specification becomes `rclone/docker-volume-rclone:arm64-1.56.2`. 341 342 We also provide the `latest` plugin tag, but since docker does not support 343 multi-architecture plugins as of the time of this writing, this tag is 344 currently an **alias for `amd64`**. 345 By convention the `latest` tag is the default one and can be omitted, thus 346 both `rclone/docker-volume-rclone:latest` and just `rclone/docker-volume-rclone` 347 will refer to the latest plugin release for the `amd64` platform. 348 349 Also the `amd64` part can be omitted from the versioned rclone plugin tags. 350 For example, rclone image reference `rclone/docker-volume-rclone:amd64-1.56.2` 351 can be abbreviated as `rclone/docker-volume-rclone:1.56.2` for convenience. 352 However, for non-intel architectures you still have to use the full tag as 353 `amd64` or `latest` will fail to start. 354 355 Managed plugin is in fact a special container running in a namespace separate 356 from normal docker containers. Inside it runs the `rclone serve docker` 357 command. The config and cache directories are bind-mounted into the 358 container at start. The docker daemon connects to a unix socket created 359 by the command inside the container. The command creates on-demand remote 360 mounts right inside, then docker machinery propagates them through kernel 361 mount namespaces and bind-mounts into requesting user containers. 362 363 You can tweak a few plugin settings after installation when it's disabled 364 (not in use), for instance: 365 ``` 366 docker plugin disable rclone 367 docker plugin set rclone RCLONE_VERBOSE=2 config=/etc/rclone args="--vfs-cache-mode=writes --allow-other" 368 docker plugin enable rclone 369 docker plugin inspect rclone 370 ``` 371 372 Note that if docker refuses to disable the plugin, you should find and 373 remove all active volumes connected with it as well as containers and 374 swarm services that use them. This is rather tedious so please carefully 375 plan in advance. 376 377 You can tweak the following settings: 378 `args`, `config`, `cache`, `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` 379 and `RCLONE_VERBOSE`. 380 It's _your_ task to keep plugin settings in sync across swarm cluster nodes. 381 382 `args` sets command-line arguments for the `rclone serve docker` command 383 (_none_ by default). Arguments should be separated by space so you will 384 normally want to put them in quotes on the 385 [docker plugin set](https://docs.docker.com/engine/reference/commandline/plugin_set/) 386 command line. Both [serve docker flags](/commands/rclone_serve_docker/#options) 387 and [generic rclone flags](/flags/) are supported, including backend 388 parameters that will be used as defaults for volume creation. 389 Note that plugin will fail (due to [this docker bug](https://github.com/moby/moby/blob/v20.10.7/plugin/v2/plugin.go#L195)) 390 if the `args` value is empty. Use e.g. `args="-v"` as a workaround. 391 392 `config=/host/dir` sets alternative host location for the config directory. 393 Plugin will look for `rclone.conf` here. It's not an error if the config 394 file is not present but the directory must exist. Please note that plugin 395 can periodically rewrite the config file, for example when it renews 396 storage access tokens. Keep this in mind and try to avoid races between 397 the plugin and other instances of rclone on the host that might try to 398 change the config simultaneously resulting in corrupted `rclone.conf`. 399 You can also put stuff like private key files for SFTP remotes in this 400 directory. Just note that it's bind-mounted inside the plugin container 401 at the predefined path `/data/config`. For example, if your key file is 402 named `sftp-box1.key` on the host, the corresponding volume config option 403 should read `-o sftp-key-file=/data/config/sftp-box1.key`. 404 405 `cache=/host/dir` sets alternative host location for the _cache_ directory. 406 The plugin will keep VFS caches here. Also it will create and maintain 407 the `docker-plugin.state` file in this directory. When the plugin is 408 restarted or reinstalled, it will look in this file to recreate any volumes 409 that existed previously. However, they will not be re-mounted into 410 consuming containers after restart. Usually this is not a problem as 411 the docker daemon normally will restart affected user containers after 412 failures, daemon restarts or host reboots. 413 414 `RCLONE_VERBOSE` sets plugin verbosity from `0` (errors only, by default) 415 to `2` (debugging). Verbosity can be also tweaked via `args="-v [-v] ..."`. 416 Since arguments are more generic, you will rarely need this setting. 417 The plugin output by default feeds the docker daemon log on local host. 418 Log entries are reflected as _errors_ in the docker log but retain their 419 actual level assigned by rclone in the encapsulated message string. 420 421 `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` customize the plugin proxy settings. 422 423 You can set custom plugin options right when you install it, _in one go_: 424 ``` 425 docker plugin remove rclone 426 docker plugin install rclone/docker-volume-rclone:amd64 \ 427 --alias rclone --grant-all-permissions \ 428 args="-v --allow-other" config=/etc/rclone 429 docker plugin inspect rclone 430 ``` 431 432 ## Healthchecks 433 434 The docker plugin volume protocol doesn't provide a way for plugins 435 to inform the docker daemon that a volume is (un-)available. 436 As a workaround you can setup a healthcheck to verify that the mount 437 is responding, for example: 438 ``` 439 services: 440 my_service: 441 image: my_image 442 healthcheck: 443 test: ls /path/to/rclone/mount || exit 1 444 interval: 1m 445 timeout: 15s 446 retries: 3 447 start_period: 15s 448 ``` 449 450 ## Running Plugin under Systemd 451 452 In most cases you should prefer managed mode. Moreover, MacOS and Windows 453 do not support native Docker plugins. Please use managed mode on these 454 systems. Proceed further only if you are on Linux. 455 456 First, [install rclone](/install/). 457 You can just run it (type `rclone serve docker` and hit enter) for the test. 458 459 Install _FUSE_: 460 ``` 461 sudo apt-get -y install fuse 462 ``` 463 464 Download two systemd configuration files: 465 [docker-volume-rclone.service](https://raw.githubusercontent.com/rclone/rclone/master/contrib/docker-plugin/systemd/docker-volume-rclone.service) 466 and [docker-volume-rclone.socket](https://raw.githubusercontent.com/rclone/rclone/master/contrib/docker-plugin/systemd/docker-volume-rclone.socket). 467 468 Put them to the `/etc/systemd/system/` directory: 469 ``` 470 cp docker-volume-plugin.service /etc/systemd/system/ 471 cp docker-volume-plugin.socket /etc/systemd/system/ 472 ``` 473 474 Please note that all commands in this section must be run as _root_ but 475 we omit `sudo` prefix for brevity. 476 Now create directories required by the service: 477 ``` 478 mkdir -p /var/lib/docker-volumes/rclone 479 mkdir -p /var/lib/docker-plugins/rclone/config 480 mkdir -p /var/lib/docker-plugins/rclone/cache 481 ``` 482 483 Run the docker plugin service in the socket activated mode: 484 ``` 485 systemctl daemon-reload 486 systemctl start docker-volume-rclone.service 487 systemctl enable docker-volume-rclone.socket 488 systemctl start docker-volume-rclone.socket 489 systemctl restart docker 490 ``` 491 492 Or run the service directly: 493 - run `systemctl daemon-reload` to let systemd pick up new config 494 - run `systemctl enable docker-volume-rclone.service` to make the new 495 service start automatically when you power on your machine. 496 - run `systemctl start docker-volume-rclone.service` 497 to start the service now. 498 - run `systemctl restart docker` to restart docker daemon and let it 499 detect the new plugin socket. Note that this step is not needed in 500 managed mode where docker knows about plugin state changes. 501 502 The two methods are equivalent from the user perspective, but I personally 503 prefer socket activation. 504 505 ## Troubleshooting 506 507 You can [see managed plugin settings](https://docs.docker.com/engine/extend/#debugging-plugins) 508 with 509 ``` 510 docker plugin list 511 docker plugin inspect rclone 512 ``` 513 Note that docker (including latest 20.10.7) will not show actual values 514 of `args`, just the defaults. 515 516 Use `journalctl --unit docker` to see managed plugin output as part of 517 the docker daemon log. Note that docker reflects plugin lines as _errors_ 518 but their actual level can be seen from encapsulated message string. 519 520 You will usually install the latest version of managed plugin for your platform. 521 Use the following commands to print the actual installed version: 522 ``` 523 PLUGID=$(docker plugin list --no-trunc | awk '/rclone/{print$1}') 524 sudo runc --root /run/docker/runtime-runc/plugins.moby exec $PLUGID rclone version 525 ``` 526 527 You can even use `runc` to run shell inside the plugin container: 528 ``` 529 sudo runc --root /run/docker/runtime-runc/plugins.moby exec --tty $PLUGID bash 530 ``` 531 532 Also you can use curl to check the plugin socket connectivity: 533 ``` 534 docker plugin list --no-trunc 535 PLUGID=123abc... 536 sudo curl -H Content-Type:application/json -XPOST -d {} --unix-socket /run/docker/plugins/$PLUGID/rclone.sock http://localhost/Plugin.Activate 537 ``` 538 though this is rarely needed. 539 540 ## Caveats 541 542 Finally I'd like to mention a _caveat with updating volume settings_. 543 Docker CLI does not have a dedicated command like `docker volume update`. 544 It may be tempting to invoke `docker volume create` with updated options 545 on existing volume, but there is a gotcha. The command will do nothing, 546 it won't even return an error. I hope that docker maintainers will fix 547 this some day. In the meantime be aware that you must remove your volume 548 before recreating it with new settings: 549 ``` 550 docker volume remove my_vol 551 docker volume create my_vol -d rclone -o opt1=new_val1 ... 552 ``` 553 554 and verify that settings did update: 555 ``` 556 docker volume list 557 docker volume inspect my_vol 558 ``` 559 560 If docker refuses to remove the volume, you should find containers 561 or swarm services that use it and stop them first.