I want to start a docker process so that it could see a folder mounted on the docker host using sshfs.
E.g.: on the host I have ~/external/dir
which was mounted via sshfs soemuser@somehost:/somepath ${HOME}/external/dir
. I ran sshfs
in the same user session where I'm trying to start docker container.
When I start docker process using -v
switch to point to the mounted directory I'm unable to access the mounted directory in the container, e.g.:
docker run -it --rm --name test -v "${HOME}/external:/external" busybox /bin/sh
/ # ls /external/
ls: /external/dir: Permission denied
When I try to mount a directory within ${HOME}/external
folder I'm unable to start docker container completely, e.g.:
docker run -it --rm --name test -v "${HOME}/external/dir/foo:/foo" busybox /bin/sh
docker: Error response from daemon: error while creating mount source path '/home/aaa/external/dir/foo': mkdir /home/aaa/external/dir: file exists.
Is there a way to somehow mount a folder that itself is sshfs-mounted on the host?
The host OS is linux.
Tried: mounting subfolder, using other docker images (e.g. centos:7).
The workaround is to copy everything from the mounted folder to the host-local folder, but it is very cumbersome due to folder's volume.
You're running into this behavior, documented in the sshfs
man page:
By default, only the mounting user will be able to access the filesystem. Access for other users can be enabled by passing
-o allow_other
. In this case you most likely also want to use-o default_permissions
.
And indeed, I am able to reproduce your problem exactly without that option, but if I run:
sshfs user@remotehost: $HOME/external/dir -o allow_other,default_permissions
Then in the container I can access the mounted directory without a problem:
$ docker run -it --rm -v $HOME/external:/external alpine
/ # ls /external
dir
/ # ls /external/dir
file1
file2
.
.
.