1

I am trying to mount a davfs2 folder (MEGA.nz) using Dockerfile.

My Dockerfile:

FROM debian:11

ENV MEGA_USER=megauser@email.com
ENV MEGA_PASS=megapassword
ENV MEGA_FOLDER=megafolder
ENV MEGA_URL=http://127.0.0.1:4443/ABCXYZ

# Install MEGA
RUN apt-get update && apt-get install -y davfs2
RUN apt-get install -y wget
RUN apt install -y apache2 
RUN apt install -y apache2-utils 
RUN wget https://mega.nz/linux/repo/Debian_11/amd64/megacmd-Debian_11_amd64.deb -P /root/
RUN apt-get install -y /root/megacmd-Debian_11_amd64.deb
RUN mkdir /mnt/mega
RUN mkdir /mnt/mega/files
RUN mega-login ${MEGA_USER} ${MEGA_PASS}
RUN mega-webdav --public /${MEGA_FOLDER}
RUN mount -t davfs ${MEGA_URL}/${MEGA_FOLDER} /mnt/mega/files 
RUN apt clean 
EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]

I can login into Mega but when it try to mount, i receive this error:

Step 14/19 : RUN mega-login ${MEGA_USER} ${MEGA_PASS}
 ---> Running in 595c8c09718f
[Initiating MEGAcmd server in background. Log: /root/.megaCmd/megacmdserver.log]
Removing intermediate container 595c8c09718f
 ---> 9699988d9b0f
Step 15/19 : RUN mega-webdav --public /${MEGA_FOLDER}
 ---> Running in 0d22f8d0b3d3
[Initiating MEGAcmd server in background. Log: /root/.megaCmd/megacmdserver.log]
                             Resuming session ...
Serving via webdav /ateka: http://127.0.0.1:4443/KDpDATyD/ateka
Removing intermediate container 0d22f8d0b3d3
 ---> 62e2d26c621f
Step 16/19 : RUN mount -t davfs ${MEGA_URL}/${MEGA_FOLDER} /mnt/mega/files
 ---> Running in b7704da9573a
The command '/bin/sh -c mount -t davfs ${MEGA_URL}/${MEGA_FOLDER} /mnt/mega/files' returned a non-zero code: 255

In my distro debian, i can do the mount. But in my Dockerfile build i cant. I would like a help to mount a davfs2 using Dockerfile.

EDIT: I copy a script to mount it in my Dockerfile.

COPY ./up.sh /root
RUN chmod +x /root/up.sh
RUN ./root/up.sh

I try to run a bash script to mount it, but i receive this:

Serving via webdav /ateka: http://127.0.0.1:4443/ABCXYZ/ateka
/sbin/mount.davfs: loading kernel module fuse
/sbin/mount.davfs: loading kernel module fuse failed
/sbin/mount.davfs: waiting for /dev/fuse to be created
/sbin/mount.davfs: can't open fuse device

  • 1
    Even if you could mount this during build, there's no way as far as I know for a mount to be saved inside a docker image. Doing it at runtime is maybe possible though. – Nick ODell Dec 21 '22 at 21:23
  • 2
    See [here](https://stackoverflow.com/questions/48402218/fuse-inside-docker) for what you need to mount a FUSE filesystem inside a container at runtime. You'll probably also need to write an entrypoint script which mounts mega and starts apache. – Nick ODell Dec 21 '22 at 21:26
  • 2
    Normally a container is prohibited from mounting filesystems, though you can change the capability set. Would it be easier to mount the filesystem on the host and then bind-mount it into the container, or create a Docker volume backed by that particular Linux mount? – David Maze Dec 22 '22 at 00:46

1 Answers1

0

Thanks for your comments. I found a way to resolve the fuse problem. But i cant run a script to mount it.

FROM debian:11

# INSTALL DAVFS2 FUSE
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -yqq
RUN apt-get install davfs2 fuse samba -yqq
# INSTALL MEGA
RUN apt-get install -y wget
RUN wget https://mega.nz/linux/repo/Debian_11/amd64/megacmd-Debian_11_amd64.deb -P /root/
RUN apt-get install -y /root/megacmd-Debian_11_amd64.deb
RUN apt clean

# CREATE FOLDERS
RUN mkdir /user-files
COPY mega.sh /root/
COPY smb.conf /etc/samba/smb.conf

And in docker-compose.yml

version: '2'

services:
  mega:
    build:
      context: .
    privileged: true
    environment:
      MEGA_USER: user@email.com
      MEGA_PASS: password
      MEGA_FOLDER: mega_folder
    volumes:
      - /user-files:/user-files

And my mega.sh

#!/bin/sh
if [ "$MEGA_USER" ]; then 
mega-login ${MEGA_USER} ${MEGA_PASS}
CMD_WEBDAV=`mega-webdav /${MEGA_FOLDER}`
MEGA_URL=${CMD_WEBDAV##*: }
echo ${MEGA_URL} ${MEGA_USER} ${MEGA_PASS} > /etc/davfs2/secrets
echo use_locks      0 >> /etc/davfs2/davfs2.conf
echo ${MEGA_URL}/ /user-files/ davfs user,rw,auto 0 0 > /etc/fstab
mount /user-files
fi

But i