Search code examples
dockerdocker-composevolumesmbcifs

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?


Solution

  • 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.