简体   繁体   English

docker 容器如何在不在主机操作系统中安装共享的情况下获得对 Windows 共享的完全访问权限?

[英]How can a docker container get full access to a windows share without mounting the share in the host OS?

I'm using docker on linux and I want to allow my containers to have full access to a windows share (named myshare with appropriate permissions set) that has the following structure:我在 linux 上使用 docker,我希望允许我的容器完全访问具有以下结构的 Windows 共享(名为 myshare,具有适当的权限集):

d:\myshare
       foo
       bar

As a test, I've verified that putting the following in /etc/fstab will create a mount that allows me to RW to the windows share.作为测试,我已经验证将以下内容放入/etc/fstab将创建一个安装,允许我 RW 到 Windows 共享。

//172.16.68.6/myshare  /home/me/foo  cifs username=myuser,password=mypass,domain=172.16.68.6,uid=1000

Instead of using /etc/fstab I'd like to be able to create a volume in docker so that I can do something like the following in my docker-compose.yml我希望能够在 docker 中创建一个卷,而不是使用/etc/fstab ,这样我就可以在 docker-compose.yml 中执行以下操作

volumes:
  - /myshare/foo:/foo

Ideally, I'd like to be able to create one volume then just append the directory name (like I did above with foo ) so I don't have to create multiple volumes.理想情况下,我希望能够创建一个卷,然后只需附加目录名称(就像我在上面对foo所做的那样),这样我就不必创建多个卷。 But so far I can't even create a mount on the docker host that connects to the windows share.但到目前为止,我什至无法在连接到 Windows 共享的 docker 主机上创建安装。 I wouldn't even know how to "peek" inside of the volume.我什至不知道如何“窥视”卷的内部。 I've tried using portainer, but it tells me the volume isn't being used.我试过使用 portainer,但它告诉我没有使用音量。

How can I create this volume and consume it (preferably in docker-compose)?我如何创建这个卷并使用它(最好在 docker-compose 中)?

I think the answer is to use a docker volume plugin. 我认为答案是使用docker volume插件。 https://docs.docker.com/engine/extend/plugins_volume/ https://docs.docker.com/engine/extend/plugins_volume/

Preferably, one already exists. 优选地,已经存在一个。 Google it, find it, and follow its instructions. 搜索它,找到它,并按照其说明进行操作。 You should be able to do it. 您应该能够做到。 Check out https://docs.docker.com/engine/extend/legacy_plugins/ for possible candidates. 查看https://docs.docker.com/engine/extend/legacy_plugins/寻找可能的候选人。

Alternatively you can write your own docker volume plugin. 或者,您可以编写自己的Docker卷插件。 Be sure to publish it for the benefit ot others. 请确保将其发布以使他人受益。 This will require a considerable amount of skill, so it might not be practical. 这将需要大量的技能,因此可能不切实际。

Here is my docker-compose.yml that is working for me.这是我的 docker-compose.yml 对我有用。 You must use the ip address in the path:您必须使用路径中的 ip 地址:

version: '3.3'
services:
  my-service:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - logs:/mnt/logs

volumes:
  spark_logs:
    driver: local
    driver_opts:
      type: cifs
      device: "//10.1.1.7/path/prd/sist/log"
      o: username=${USER},password=${PASS},file_mode=0444,dir_mode=0444

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

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