I am trying to mount a sshfs for a service. There is my Docker Stack config:
...
myservice:
...
volumes:
- "sshfs_volume:/home/app/web/media:rw"
...
volumes:
sshfs_volume:
driver: vieux/sshfs:latest
driver_opts:
sshcmd: "username@myhost:shared_storage"
allow_other: ""
password: "*****"
The command "ls -la /home/app/web/media" in a container returns the following result:
total 12
drwxrwxr-x 1 1000 1001 4096 Aug 9 21:55 .
drwxr-sr-x 1 app app 4096 Aug 9 21:54 ..
-rw-r--r-- 1 1000 1001 0 Aug 9 21:55 dump
-rw-r--r-- 1 1000 1001 0 Aug 9 21:17 tmp.txt
This files were created by me via sshfs command in the same host where docker container was running. It means that volume was mounted correctly (maybe excepting permission issues).
The problem is that i can't write files in containers in this volume. For example:
> touch /home/app/web/media/t2.txt
touch: /home/app/web/media/t2.txt: Permission denied
I have tried to restart Docker Daemon, remove volumes and recreate them. The result is the same, it didn't help.
I solved it by adding to my service this parameter: user: "100:101"
and adding this parameters to the volume: uid: 100
and gid: 101
in the docker-stack file. My final docker-stack file:
...
myservice:
...
user: "100:101"
volumes:
- "sshfs_volume:/home/app/web/media:rw"
...
volumes:
sshfs_volume:
driver: vieux/sshfs:latest
driver_opts:
sshcmd: "username@myhost:shared_storage"
allow_other: ""
default_permissions: ""
reconnect: ""
uid: 100
gid: 101
password: "*****"