Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mounting a network folder to a Docker container on Windows 10

Tags:

docker

windows

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.

like image 597
Sam Avatar asked Oct 14 '16 17:10

Sam


People also ask

How do I share a Windows folder to a Docker container?

In order to share Windows folders with Docker containers, you first need to configure the "Shared Drives" option in Docker settings. Once the Shared Drives option is configured, you can mount any folder on shared drives with the "-v" (volume) flag.

How do I mount my current working directory to my Docker container in Windows?

Open Settings on Docker Desktop (Docker for Windows). Select Shared Drives. Select the drive that you want to use inside your containers (e.g., C). Click Apply.


1 Answers

Do this with Windows based containers

Go to Microsoft documentation https://docs.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.

like image 132
thetillhoff Avatar answered Sep 28 '22 08:09

thetillhoff