TL;NR
I have successfully mounted a remote drive in a docker container via the rclone Docker Volume Plugin, and everything works fine within the container.
I am wondering if it is possible to map that mounted drive inside the container to a local folder on the host machine?
Setup
Install the rclone Docker Volume Plugin
docker plugin install rclone/docker-volume-rclone:amd64 --alias rclone --grant-all-permissions
Set the Volume Plugin
docker plugin rclone disable
docker plugin set rclone RCLONE_VERBOSE=2 args="--uid 1000 --gid 1000 --umask 022 --buffer-size 128M"
docker plugin rclone enable
Configure the container with compose.yaml
version: "3.8"
networks:
default:
name: base
driver: bridge
attachable: true
volumes:
gd:
name: gd
driver: rclone
driver_opts:
remote: 'gd:'
allow_other: 'true'
vfs_cache_mode: full
vfs_cache_max_size: 100G
vfs_cache_max_age: 12h
dir_cache_time: 168h
poll_interval: 0
services:
busybox:
image: busybox:latest
container_name: busybox
tty: true
environment:
- PUID=1000
- PGID=1000
- TZ=EST
volumes:
- gd:/mnt/gd
Behavior Observed
Inside the container busybox
up the container:
❯ docker compose up -d
exec the shell of the container:
❯ docker exec -it c2c171d2366139c65fea6e4d82e11abe00d4a7265572ed955678f406b4c43a30 /bin/sh -c eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)
access the remote drive within the container:
/ # ls -aln /mnt/gd
total 4
drwxr-xr-x 1 1000 1000 0 Jul 3 03:40 .
drwxr-xr-x 10 1000 998 4096 Jul 6 17:00 ..
drwxr-xr-x 1 1000 1000 0 Aug 13 2021 folder1
drwxr-xr-x 1 1000 1000 0 Sep 6 2021 folder2
drwxr-xr-x 1 1000 1000 0 May 13 03:28 folder3
/ #
Everything looks fine in the container, the remote drive mounted by the rclone driver from the volume plugin works as expected.
Question
So, when I am inside the container
busybox
, I can access the remote drivegd
fine at/mnt/gd
(container fs). I am wondering if it is possible to map (or bind) a local folder outside the docker container, say~/gd
(host machine fs) to the volumegd
mounted within thebusybox
docker container? So that I don’t need to mount the remote drive with another dedicated rclone daemon.
Approach Attempted (but not working)
Initially, I thought it would achieve what I want if I bind a host machine folder to the parent folder of the directory that the remote drive is mounted on, because this way the mounted drive will be reflected under the host machine folder outside the container. Like this:
Create the host machine folder ~/mount
❯ mkdir -p ~/mount
❯ ls -aln ~/mount
total 8
drwxr-xr-x 2 1000 998 4096 Jul 6 19:54 ./
drwx------ 13 1000 998 4096 Jul 6 19:54 ../
Bind the host machine folders in compose.yaml
version: "3.8"
networks:
default:
name: base
driver: bridge
attachable: true
volumes:
+ mount:
+ name: local.mount
+ driver: local
+ driver_opts:
+ device: ~/mount
+ o: bind
+ type: local
gd:
name: gd
driver: rclone
driver_opts:
remote: 'gd:'
allow_other: 'true'
vfs_cache_mode: full
vfs_cache_max_size: 100G
vfs_cache_max_age: 12h
dir_cache_time: 168h
poll_interval: 0
services:
busybox:
image: busybox:latest
container_name: busybox
tty: true
environment:
- PUID=1000
- PGID=1000
- TZ=EST
volumes:
+ - ~/mount:/mnt
- gd:/mnt/gd
restart the container to apply the newly updated compose.yaml
❯ docker compose down && docker compose pull && docker compose up -d
check the remote drives outside the container
❯ ls -aln ~/mount
total 12
drwxr-xr-x 3 1000 998 4096 Jul 6 20:02 ./
drwx------ 13 1000 998 4096 Jul 6 19:58 ../
drwxr-xr-x 2 1000 998 4096 Jul 6 20:02 gd/
❯ ls -aln ~/mount/gd
total 8
drwxr-xr-x 2 1000 998 4096 Jul 6 20:02 ./
drwxr-xr-x 3 1000 998 4096 Jul 6 20:02 ../
We can see the remote drive mounted inside the container is correctly reflected in the host machine folder, however, its content is empty.
Summary
So basically what I want to achieve is
remote drive <=> docker volume plugin <=> docker container <=> host machine filesystem
Please let me know if there is a viable way to achieve this.
Any help is much appreciated. Thank you!