简体   繁体   English

Windows 上 Docker-compose 中的 SMB/CIFS 卷

[英]SMB/CIFS volume in Docker-compose on Windows

I have a NAS with a shared CIFS/SMB share that I would like to mount as a volume using docker-compose on Windows.我有一个共享 CIFS/SMB 共享的 NAS,我想在 Windows 上使用 docker-compose 将其挂载为卷。

I have read through multiple suggestions (for instance using plugins, mounting it in Windows to give it a drive letter) without finding anything that I can get working.我已经阅读了多项建议(例如使用插件,将其安装在 Windows 中以提供驱动器号),但没有找到任何可以工作的东西。 I understand it's not 100 % straightforward since I'm accessing it from inside another OS.我知道这不是 100% 简单的,因为我是从另一个操作系统内部访问它。 But it sounds like something that should be possible.但这听起来应该是可能的。

So say that I have a network path, \\my-nas\share , how would I go about mounting this inside a docker container using docker-compose on a Windows host? So say that I have a network path, \\my-nas\share , how would I go about mounting this inside a docker container using docker-compose on a Windows host?

I had completely misunderstood this docker docs page where it says我完全误解了这个 docker 文档页面,上面写着

The built-in local driver on Windows does not support any options.

That does not mean that you can't use the cifs driver in Windows.这并不意味着您不能在 Windows 中使用 cifs 驱动程序。

The solution is very simple解决方法很简单

services:
  my-service:
    volumes:
      - nas-share:/container-path

volumes:

  nas-share:
    driver_opts:
      type: cifs
      o: "username=[username],password=[password]"
      device: "//my-nas/share"

Replace [username] and [password] with the actual username and password for the NAS and it works perfectly.[username][password]替换为 NAS 的实际用户名和密码,它可以完美运行。

This worked for me using a windows container on WindowsServer2019 host.这对我使用 WindowsServer2019 主机上的 windows 容器很有用。 It requires version 1705 or newer:它需要版本 1705 或更高版本:
https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/persistent-storage#bind-mounts https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/persistent-storage#bind-mounts

First mount the file share to the host.首先将文件共享挂载到主机。
$creds = Get-Credential New-SmbGlobalMapping -RemotePath \contosofileserver\share1 -Credential $creds -LocalPath G: $creds = Get-Credential New-SmbGlobalMapping -RemotePath \contosofileserver\share1 -Credential $creds -LocalPath G:

Then map the drive as normal in compose:然后 map 驱动器正常组成:

services:
  my-service:
    volumes:
    - Z:\:/container-path

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

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