Docker 容器无法在 cifs 共享内写入

发布于 2025-01-10 13:18:08 字数 706 浏览 6 评论 0原文

我有一个用于使用多个容器构建的媒体服务器的 docker compose,我希望这些容器能够读/写安装在主机上的 cifs 共享,在尝试了多种方法之后,我似乎无法让它们写入。 这是已安装的共享:/etc/fstab

//192.168.X.X/Media /mnt/Media cifs cache=loose,credentials=/root/.smbcrd,vers=3.0 0 0

,这是多个容器 docker compose 之一:

 emby:
image: linuxserver/emby
container_name: emby
environment:
  - PUID=998
  - PGID=100
  - TZ=Europe/Paris
  - UMASK_SET=022 #optional
volumes:
  - /mnt/Media/Configs/Emby:/config
  - /mnt/Media/Series:/data/series
  - /mnt/Media/Films:/data/movies
ports:
  - 8096:8096
  - 8920:8920 
restart: unless-stopped

我正在学习 docker,我不认为在每个容器内安装 cifs 共享是解决方案,我需要在卷中安装共享吗我的 docker compose 部分?,共享的是 Synology nas。 有人可以帮忙吗?

I have a docker compose for a media server i'm building using multiple containers, i want these containers to be able to R/W a cifs share mounted on host, after trying multiple ways i can't seem get them to write.
here's the mounted share : /etc/fstab

//192.168.X.X/Media /mnt/Media cifs cache=loose,credentials=/root/.smbcrd,vers=3.0 0 0

and here's one of the multiple containers docker compose :

 emby:
image: linuxserver/emby
container_name: emby
environment:
  - PUID=998
  - PGID=100
  - TZ=Europe/Paris
  - UMASK_SET=022 #optional
volumes:
  - /mnt/Media/Configs/Emby:/config
  - /mnt/Media/Series:/data/series
  - /mnt/Media/Films:/data/movies
ports:
  - 8096:8096
  - 8920:8920 
restart: unless-stopped

I'm learning docker and i don't think mounting the cifs share inside every container is the solution,do i need to mount the share in volumes section of my docker compose ?,the share is a synology nas.
can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔芯 2025-01-17 13:18:08

Docker 的 CIFS 可能性

让容器挂载(不好的方法)

services:
  name:
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
    security_opt:
      - "apparmor=unconfined"

Dockerfile:
ENTRYPOINT ["/bin/bash", "mount.sh" ]

mount.sh:

#!/bin/bash

mkdir /mnt/whatever
mount -v -t cifs -o username=xx,password=xx,vers=SMB-Version-Number,dir_mode=0744,file_mode=0744 //IP/Path /mnt/whatever

<start your container logic>

由于安全性非常差,这是一种不好的方法,但在某些用例中可能会有所帮助。

让 docker mount

services:
  name:
     volumes:
      - my_mount:/mnt/whatever

volumes:
  my_mount: 
    driver_opts:
      type: cifs
      o: username=xx,password=xx,vers=SMB-Version-Number
      device: //IP/Path

让主机挂载

mount -t cifs -o username=xx,password=xx, \               
  uid=dockeruid,forceuid, \
  gid=dockergid,forcegid, \                  
  file_mode=744,dir_mode=744 //IP/Path /mnt/whatever   

运行 docker 容器,然后使用此用户:

services:
  name:
    user: "dockeruid:dockergid"
    volumes:
      - /mnt/whatever:/mnt/whatever

CIFS Possibilities for Docker

Let Container mount (bad approach)

services:
  name:
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
    security_opt:
      - "apparmor=unconfined"

Dockerfile:
ENTRYPOINT ["/bin/bash", "mount.sh" ]

mount.sh:

#!/bin/bash

mkdir /mnt/whatever
mount -v -t cifs -o username=xx,password=xx,vers=SMB-Version-Number,dir_mode=0744,file_mode=0744 //IP/Path /mnt/whatever

<start your container logic>

Bad approach due to very bad security, but in some use-cases could be helpful.

Let docker mount

services:
  name:
     volumes:
      - my_mount:/mnt/whatever

volumes:
  my_mount: 
    driver_opts:
      type: cifs
      o: username=xx,password=xx,vers=SMB-Version-Number
      device: //IP/Path

Let host mount

mount -t cifs -o username=xx,password=xx, \               
  uid=dockeruid,forceuid, \
  gid=dockergid,forcegid, \                  
  file_mode=744,dir_mode=744 //IP/Path /mnt/whatever   

run docker containers then with this user:

services:
  name:
    user: "dockeruid:dockergid"
    volumes:
      - /mnt/whatever:/mnt/whatever
深爱成瘾 2025-01-17 13:18:08

您还可以将其添加到

# /etc/fstab
//IP/path /my/path/to/share cifs credentials=/my/creds,noperm,uid=xx,gid=xx,file_mode=0640,dir_mode=0750,rw,noserverino 0 0

Dockerfile 中的

...
ADD config/rancher/<instance>/etc/fstab /etc/fstab.added
RUN touch /etc/fstab
RUN cat /etc/fstab.added >> /etc/fstab
...

FSTAB 中,但如果您遇到此问题:“无法应用新功能集。”

在部署脚本中添加 securityContext.capability.privileged=true,如下所示:

apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo-4
spec:
  containers:
  - name: sec-ctx-4
    image: gcr.io/google-samples/node-hello:1.0
    securityContext:
      capabilities:
        privileged: true

Bibliography:

如果您在根帐户执行“挂载”时遇到问题,看看 Dockerfile JBOSS 无法访问本地

You can also add it in the FSTAB

# /etc/fstab
//IP/path /my/path/to/share cifs credentials=/my/creds,noperm,uid=xx,gid=xx,file_mode=0640,dir_mode=0750,rw,noserverino 0 0

In the Dockerfile

...
ADD config/rancher/<instance>/etc/fstab /etc/fstab.added
RUN touch /etc/fstab
RUN cat /etc/fstab.added >> /etc/fstab
...

But if you have this issue : "Unable to apply new capability set."

add in the deployment script securityContext.capabilities.privileged=true, as bellow:

apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo-4
spec:
  containers:
  - name: sec-ctx-4
    image: gcr.io/google-samples/node-hello:1.0
    securityContext:
      capabilities:
        privileged: true

Bibliography:

if you have an issue with the root account to perform "mount", have a look at Dockerfile JBOSS don't access local

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文