23

I use SSHFS to mount a remote filesystem on my host and I want to be able to access it from inside a Docker container.

I mount the remote filesystem

sshfs -o idmap=user,uid=$(id -u),gid=$(id -g) user@remote:directory /path/to/sshfs

And, using Docker, I get the following errors depending on me using --mount:

docker run  -it -v /path/to/sshfs:/target myimage bash
docker: Error response from daemon: error while creating mount source path '/path/to/sshfs': mkdir /path/to/sshfs: file exists.

or -v:

docker run -it  --mount src=/path/to/sshfs,target=/target,type=bind  myimage bash
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /path/to/sshfs.
See 'docker run --help'

Is it possible to mount a sshfs mountpoint into a container?

Ralph
  • 333
  • 1
  • 2
  • 5

3 Answers3

30

Requires the following steps:

  1. uncomment user_allow_other in /etc/fuse.conf

  2. unmount the FUSE filesystem

  3. remount the FUSE filesystem with sshfs -o allow_other user@.... (making sure to include the -o allow_other option)

  4. try starting the container again

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • 4
    Thanks! I did as you said and then mounted with `sshfs -o allow_other` and it worked! – Ralph Dec 31 '18 at 21:31
  • Great, it works fine for me, even without the `-o allow_other` option added – stdcerr Mar 13 '22 at 16:57
  • If you cannot use `-o allow_other` because `user_allow_other` isn't set and you're not allowed to change that, you might find my answer below helpful: Instead of mounting your directory, mount its parent. – Skeeve May 17 '23 at 05:47
0

Detailed step by step with external references:

  1. Create and copy an SSH key to the remote server

Only need to do this the first time we make a SSHFS mount. Here's an example on how to do this in ubuntu.

  1. Mount the Remote File System(s) Over SSHFS

Follow the steps from this tutorial.

  1. Mount a SSHFS volume into the Docker instance

docker run -it -v /path/to/sshfs:/target myimage bash

trevi
  • 101
0

I had the same issue but couldn't use "allow_other", as I have no root permission. But what I found out is, that you can mount the mount-point's parent.

So your example would work for me like this:

docker run  -it -v /path/to:/target myimage bash

Of course it's then not avalable as /target but only as /target/sshfs.

Skeeve
  • 101