7

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?

orderlyfashion
  • 531
  • 1
  • 4
  • 14

2 Answers2

24

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.

orderlyfashion
  • 531
  • 1
  • 4
  • 14
  • 4
    This is what worked for me, however I had to make one addition for it to recognize a hostname (my-nas in this case) vs an IP address. In the Options statement, I had to add the addr parameter. It ended up looking something like this `o: "username=[username],[password=[password],addr=my-nas` where my-nas was the hostname of the server I wanted to connect to. I found this recommendation here [https://github.com/moby/moby/issues/42007] – Khoward Oct 19 '21 at 19:00
  • 1
    had the same issue windows cifs with linux container and got it working by replacing hostname with ip. – prasadmadanayake Mar 14 '22 at 05:54
  • I have this exact same docker setup and I'm trying to connect to my qnap nas share. I added the addr option which got rid of an 'invalid argument' error that I was getting. Now I am getting a 'permission denied' error. Anyone know what could be causing this error? I've tried adding uid, gid, noperm but nothing has worked for me. I am able to map the share as a network drive in Windows and read and write to it but something about how docker is doing it is not working when trying to create a volume. – CaMiX Jul 16 '22 at 22:58
1

This worked for me using a windows container on WindowsServer2019 host. It requires version 1705 or newer:
https://learn.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
MikeF
  • 764
  • 9
  • 26