29

I'm trying to mount a network folder with a Docker container on Windows 10 with the following syntax. Using UNC paths does not work. I'm running it under Hyper-V and the stable version of Docker.

docker run -v \\some\windows\network\path:/some/local/container

Before I was using Docker Toolbox, and I could map a network share to an internal folder with VirtualBox. I've tried adding the network share as a drive, but it doesn't show up as an available drive under the settings panel.

Currently I'm using mklink to mirror a local folder to the network folder, but I'd like to not depend on this as a solution.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sam
  • 757
  • 3
  • 11
  • 14

1 Answers1

7

Do this with Windows based containers

Go to Microsoft documentation https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/persistent-storage#smb-mounts.

There you'll find information about how to mount a network drive as a volume in a windows container.


Do this with Linux based containers

Is currently (as of 2019-11-13) not possible. BUT you can use a plugin: https://github.com/ContainX/docker-volume-netshare

I didn't use it, so I have no experience with it. Just found it during my research and wanted to add this as a potential solution.

Recommended solution

While researching on this topic I felt that you should probably mount the drive from within the container. You can pass required credentials either via file or parameters.

Example for credentials as file

You would require to install the package cifs-utils in the container, add

COPY ./.smbcredentials /.smbcredentials

to the Dockerfile and then run the following command after the container is started:

sudo mount -t cifs -o file_mode=0600,dir_mode=0755,credentials=/.smbcredentials //192.168.1.XXX/share /mnt


Potential duplicate

There was another stackoverflow thread on this topic here: Docker add network drive as volume on windows

The answer provided there (https://stackoverflow.com/a/57510166/12338776) didn't work for me though.

thetillhoff
  • 451
  • 4
  • 8
  • 2
    Could you adjust your answer to be a little more detailed and specific on how this answers the question rather then simply linking to other sources. Thanks – TroySteven Nov 13 '19 at 15:07
  • Using `cifs-utils` worked for me. my base image is `mcr.microsoft.com/powershell:centos-7` – Collin Thomas Jan 26 '21 at 22:15