linux - 在 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
解决方案
推荐阅读
- asp.net - 新清除 Web 项目 Ubuntu 18.04 中的 ASP.NET Core 错误 CS1022
- jenkins-plugins - 如何在 Jenkins 中添加自定义网页?
- python - ModuleNotFoundError:没有名为 darkflow.cli 和“nms”的模块
- c# - 如何在没有命令的情况下发送消息?
- ios - Objective-C 返回可变大小的对象可能未初始化
- java - “AWT-EventQueue-0” java.lang.StackOverflowError - 尝试创建 JTree 文件夹结构时
- matlab - 如何标记此预测示例 Matlab
- codeigniter - 无法上传大小为 5MB 的 excel 文件并出现以下错误
- drupal-8 - 节点预览页面的 Drupal 8 主题建议
- ruby-on-rails - 如何将递归/嵌套 OpenStruct 对象转换为哈希