简体   繁体   English

来自另一个容器的 Docker 中的 mount.cifs 需要特权

[英]mount.cifs in Docker from another container requires privilege

My use case is a transcode farm that reads inputs from a Samba share and writes it to another.我的用例是一个转码农场,它从 Samba 共享读取输入并将其写入另一个共享。

Using mount.cifs in Docker requires both SYS_ADMIN and DAC_READ_SEARCH capabilities.在 Docker 中使用mount.cifs需要SYS_ADMINDAC_READ_SEARCH功能。 I am able to use two hosts and run smbd on one host, and mount its share on another host.我能够使用两台主机并在一台主机上运行smbd ,并将其共享安装在另一台主机上。 (Both smbd and mount are ran inside containers, just in different host.) smbdmount都在容器内运行,只是在不同的主机中。)

However, I cannot, using the same mount command, mount the Samba share on the host with the container that's running smbd .但是,我无法使用相同的mount命令将 Samba 共享挂载到运行smbd的容器的主机上。

EDIT: It works on Docker Desktop but fails in a Linux host.编辑:它适用于 Docker 桌面,但在 Linux 主机中失败。 (With the same docker engine server version) (使用相同的docker引擎服务器版本)

TL;DR the following Docker Compose fails UNLESS I give it privileged access. TL;DR 以下 Docker Compose 失败,除非我给它特权访问。

Environments: Working on Docker for Mac, Not working on bare-metal Linux (Ubuntu 18.04.4 4.15.0-91-generic Docker 19.03.8 containerd 1.2.13), Not working on Hyper-V-virtualized Linux (Ubuntu 19.04 5.0.0-38-generic Docker 19.03.6 containerd 1.2.13)环境:使用 Docker for Mac,不适用于裸机 Linux(Ubuntu 18.04.4 4.15.0-91-generic Docker 19.03.8 containerd 1.2.13),不适用于 Hyper-V 虚拟化 Linux(Ubuntu 19.04 5.0) .0-38-通用 Docker 19.03.6 容器 1.2.13)

version: '3.4'

services:
  samba:
    image: dperson/samba
    environment:
      TZ: 'EST5EDT'
    networks:
      - default
    ports:
      - "137/udp"
      - "138/udp"
      - "139/tcp"
      - "445/tcp"
    tmpfs:
      - /tmp
    restart: unless-stopped
    stdin_open: true
    tty: true
    volumes:
      - /samba-data
    command: '/bin/bash -c "touch /samba-data/file.txt && samba.sh -s \"data;/samba-data\" -u \"bob;bob\" -p"'
  mounter:
    image: ubuntu
    command: '/bin/bash -c "apt update && apt install -y cifs-utils && mkdir /samba-data && mount -v -o username=bob,password=bob,vers=3.0,ro,port=445 //samba/data /samba-data"'
    tty: true
#   privileged: true
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
networks:
  default:

My questions,我的问题,

  1. Why is privileged required when running on the same Docker host?为什么在同一个 Docker 主机上运行时需要特权?
  2. Can I make it more restrictive (by giving it only what it needs)?我可以让它更严格吗(只给它需要的东西)?

Is there anything in your use case, requiring the mount to be done inside the container ?您的用例中是否有任何东西需要在容器内完成安装? How about letting docker handle the mount ?让 docker 处理 mount 怎么样?

In your example, you are starting a container to expose a samba share, and another one to read from it.在您的示例中,您正在启动一个容器以公开 samba 共享,并启动另一个容器以从中读取。 How about simply binding both containers to the same docker volume (ie define a named volume at the top level of your docker-compose, and use it in both services) ?如何简单地将两个容器绑定到同一个 docker 卷(即在 docker-compose 的顶层定义一个命名卷,并在两个服务中使用它)? That's the usual way to share a mount between container, and this doesn't require privileges or open ports.这是在容器之间共享挂载的常用方法,并且不需要特权或开放端口。 See this SO answer for example.例如,请参阅此 SO 答案

If this "shared folder" must be CIFS (because in real life it's not a samba container, but a Windows server ?), you can define the volume with a volume-driver parameter pointing to a docker volume plugin which supports CIFS, such as this one or this other one .如果这个“共享文件夹”必须是 CIFS(因为在现实生活中它不是 samba 容器,而是 Windows 服务器?),您可以使用指向支持 CIFS 的docker 卷插件volume-driver参数定义卷,例如这个这个另一个 Your "mounter" container would start with the CIFS share already mounted.您的“mounter”容器将从已经安装的 CIFS 共享开始。 No need to mount from inside the container, hence no need for a privileged container or extended caps.不需要从容器内部安装,因此不需要特权容器或扩展帽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM