简体   繁体   中英

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.

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. I understand it's not 100 % straightforward since I'm accessing it from inside another OS. 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?

I had completely misunderstood this docker docs page where it says

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.

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.

This worked for me using a windows container on WindowsServer2019 host. It requires version 1705 or newer:
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:

Then map the drive as normal in compose:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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