2

I use php:7.3.2-cli-alpine3.9 as my base image. I also need SSHFS installed inside container since PHP library I use relies on it. I know there are many answers with "if you install SSHFS inside container you are doing it wrong" but in my case I need this software installed inside container not on host.

In my Dockerfile I have

RUN apk update && apk add sshfs;

This command is executed without errors:

fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
v3.9.3-21-g265a28802e [http://dl-cdn.alpinelinux.org/alpine/v3.9/main]
v3.9.3-15-g583c0d55e9 [http://dl-cdn.alpinelinux.org/alpine/v3.9/community]
OK: 9764 distinct packages available
(1/12) Installing openssh-keygen (7.9_p1-r4)
(2/12) Installing openssh-client (7.9_p1-r4)
(3/12) Installing fuse-common (3.2.6-r1)
(4/12) Installing fuse3 (3.2.6-r1)
(5/12) Installing libffi (3.2.1-r6)
(6/12) Installing libintl (0.19.8.1-r4)
(7/12) Installing libuuid (2.33-r0)
(8/12) Installing libblkid (2.33-r0)
(9/12) Installing libmount (2.33-r0)
(10/12) Installing pcre (8.42-r1)
(11/12) Installing glib (2.58.1-r2)
(12/12) Installing sshfs (3.5.1-r0)
Executing busybox-1.29.3-r10.trigger
Executing glib-2.58.1-r2.trigger
OK: 25 MiB in 44 packages

But when I am trying to mount remote host

'/usr/bin/sshfs' -C -o reconnect -o 'Port=22' -o 'UserKnownHostsFile=/ssh/known_hosts' -o StrictHostKeyChecking=yes -o 'IdentityFile=/ssh/<FILE>' -o PasswordAuthentication=no '<USER>@<HOST>:/' '/fuse/'

I am getting:

fuse: device not found, try 'modprobe fuse' first

When I am running it I am getting:

modprobe: can't change directory to '/lib/modules': No such file or directory

Am I missing any packages? What else needs to be installed?

Thanks.

Evgeny M
  • 417
  • 7
  • 15
  • Have you tried creating that directory (in the dockerfile) before installing the sshfs package? Or even create it after installing, just to see if it works after that. – Scrambo Apr 15 '19 at 20:12
  • 1
    You can't load a kernel module from inside a Docker container. You may or may not be successful loading the relevant module outside of Docker; or else running the workload in a VM with its own kernel (with a known version) would likely work. – David Maze Apr 15 '19 at 20:27
  • @Scrambo I am actually tried but it did not work like I expected. Issue is not directory absence but what is missing inside. – Evgeny M Apr 16 '19 at 13:33
  • @DavidMaze Thanks, could you please elaborate a little bit more? I am only interested in SSHFS working inside container. It relies on kernel module but other software does that as well while Docker "proxy" host's kernel. Is it only Alpine related issue and centos/ubuntu image will work? – Evgeny M Apr 16 '19 at 13:39

1 Answers1

3

In order to run SSHFS inside container it requires privileged permissions.

Install SSHFS by adding this line in Dockerfile: RUN apk update && apk add sshfs;

Run container: docker run --privileged=true -it --rm --name alpine-app transfers-image

Evgeny M
  • 417
  • 7
  • 15