如何在Dockerfile中挂载一个Mega文件夹

xxe27gdn  于 2022-12-26  发布在  Docker
关注(0)|答案(1)|浏览(246)

我正在尝试使用Dockerfile挂载davfs2文件夹(MEGA.nz)。
我的停靠文件:

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"]

我可以登录到Mega,但当它尝试挂载时,我收到此错误:

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

在我的debian发行版中,我可以挂载。但是在我的Dockerfile版本中我不能。我想得到一个使用Dockerfile挂载davfs2的帮助。
编辑:我复制了一个脚本,将其挂载到我的Dockerfile中。

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

我尝试运行bash脚本来挂载它,但收到以下消息:

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
aemubtdh

aemubtdh1#

谢谢你的评论。我找到了一个解决保险丝问题的方法。但是我不能运行脚本来安装它。

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

在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

我的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

但是我

相关问题