首页 > 解决方案 > 在 Docker 容器中使用 root 用户挂载 CIFS 时出错

问题描述

我正在尝试以 root 用户身份挂载 CIFS 共享驱动器(Azure 存储文件服务),但仍然不允许挂载并抛出错误:

mount: 权限被拒绝(你是 root 吗?)

请找到以下 Docker 文件和入口点文件。

码头工人文件

FROM alpine:latest

USER root

RUN apk update \
    && apk add --no-cache ca-certificates wget

RUN apk add postgresql-client cifs-utils

COPY ./mount-drive.sh /tmp/mount-drive.sh 

RUN chmod +X /tmp/mount-drive.sh 

RUN apk --no-cache add sudo

ENTRYPOINT [ "sh", "/tmp/mount-drive.sh" ]

入口点文件

mkdir /mnt/test

if [ ! -d "/etc/smbcredentials" ]; then
    mkdir /etc/smbcredentials
fi

if [ ! -f "/etc/smbcredentials/<storageaccountname>.cred" ]; then
    sh -c 'echo "username=<storageaccountname>" >> /etc/smbcredentials/<storageaccountname>.cred'
    sh -c 'echo "password=PASSWORD" >> /etc/smbcredentials/<storageaccountname>.cred'
fi

chmod 600 /etc/smbcredentials/<storageaccountname>.cred

sh -c 'echo "//<storageaccountname>.file.core.windows.net/test /mnt/test cifs nofail,vers=3.0,credentials=/etc/smbcredentials/<storageaccountname>.cred,dir_mode=0777,file_mode=0777,serverino" >> /etc/fstab'


sudo -u root mount --t cifs //<storageaccountname>.file.core.windows.net/test /mnt/test -o vers=3.0,credentials=/etc/smbcredentials/<storageaccountname>.cred,dir_mode=0777,file_mode=0777,serverino

标签: linuxdocker

解决方案


推荐阅读