Docker Community Forums

Share and learn in the Docker community.

How to map LAN network share to Docker volume?

My host machine is Windows 10 in LAN. The LAN has same network file storage shares.
How to map LAN network share to Docker volume to make the share accessible inside of docker?

I.e. my dockerized ASP NET Core cross-platform app should enumerate files in the LAN like this

public void ConfigureServices(IServiceCollection services)
{
    try
    {
        Console.WriteLine("****TEST: GetFiles");
        string[] filePaths = Directory.GetFiles(@"\\Share1\FolderMix\");
        foreach (var f in filePaths)
        {
            Console.WriteLine(@"***file: {0}", f);
        }
    }
    catch(Exception x)
    {
        Console.WriteLine(@"***Exception: {0}", x.Message);
    }

To not bloat the required capabilities unnecessarily, the recommended approach is to use volumes instead (pointing to your CIFS shares) and map them into a folder inside the container, then use them in your containerized app as you would use any local folder.

Either create your volume first and then use it in docker run commands:

docker volume create \
    --driver local \
    --opt type=cifs \
    --opt o=username={smbuser},password={smbpass},uid={UID for mount},gid={gid for mount},vers=3.0 \
    --opt device=//Share1/FolderMix \
    foldermix

or declare it in a docker-compose.yml:

volumes:
  foldermix:
    driver_opts:
      type: cifs
      o: username={smbuser},password={smbpass},uid={UID for mount},gid={gid for mount},vers=3.0
      device: //Share1/FolderMix

Make sure to use valid credentials for smbuser/smbpass and that the uid/gid matches those of the user inside the container that start your application inside the container.

Thanx, yet some questions:

  1. What is recommended to use in this case: CIFS or NFS?
  2. I have a netwotk share with permissions for Everyone Full rights. What should I use here
    o: username={smbuser},password={smbpass},uid={UID for mount},gid={gid for mount},
    smbuser?
    smbpass?
    UID?
    gid?

My situation allows to use NFS v4 and I prefer it over CIFS (not NFS v3 though!) . Instead of requiring user credentials, you need to whitelist the docker host in the NFS export (of the server) to allow access to the share.

Appart from that: it is up to you and whatever is given in your environment.