简体   繁体   中英

Mounting a network folder to a Docker container on Windows 10

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.

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.

I'm not a Windows user so I can't test this answer, but looking at the Docker code it seems that you need to prepend your path with \\\\?\\ .

So you should run:

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

You shouldn't do that because docker expects the files to be local and read/writes will time out on bad connections.

You should try to make your software connect to your network share directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM