Mount windows share in a docker container

I am trying to access a network drive from my docker container, but the mounted directory in the container is shown as empty.

The host docker runs on has Windows 10 Enterprise LTSC, Build 17763 (which seems to not support wsl2 yet, but we don’t want to update it. Docker version is 24.0.6 The image is continuumio/miniconda3 I have added the file share <address>/<folder> in docker desktop under resources. I can access the network drive from the host. I can also mount C:/ and D:/ with the -v flag successfully.

my best attempt for the docker run options has been:
docker run --network=host --rm -v //<address>/<folder>:/mount -it --entrypoint /bin/bash --name my_container my_image Also, the (empty) directory /mount seems remember when I put some test.txt in it from within the container, even when I run a new container.

some other attempts:

I have also mapped the letter X: to //<address>/<folder>: on the host, and using X: instead of //<address>/<folder>: in the -v flag gives the message: “docker wants access to U:\C<address>/<folder>. Do you want to share it?”. Accepting this gives the error "docker: Error response from daemon: error while creating mount source path '/host_mnt/uC/<adress>/<folder>': mkdir /host_mnt/uC: operation not permitted. " I also dont know what’s going on there.

I also tried my laptop, which has a wsl2 docker version, and it also didn’t work there. And I also tried: apt-get update && apt-get install -y cifs-utils mount -t cifs //<address>/<folder> /mount -o username=<user>,password=<password>,vers=3.0 but got: "Unable to apply new capability set. " which doesn’t tell me anything of course.

And: docker volume create --driver local --opt type=cifs --opt device=//<adress>/<folder> --opt o=addr=shareddrivename,username=...,password=...,vers=3.0 myvol docker run --network=host --rm -v myvol:/mnt/mount2 -it --entrypoint /bin/bash --name thor2 my_image
this gave the error: docker: Error response from daemon: error while mounting volume '/var/lib/docker/volumes/myvol/_data': error resolving passed in network volume address: lookup shareddrivename on 192.168.x.x:53: read udp 192.168.x.y:56258->192.168.x.x:53: i/o timeout.

I have basically just been trying 100 different things, but I dont know how to get feedback on why the mounting doesn’t work. Any ideas, specifically on how to systematically approach this?

I tried mounting a net drive via docker run --network=host --rm -v //<address>/<folder>:/mount -it --entrypoint /bin/bash --name my_container my_image expected the files of the drive to show up directory was empty

1 Like

Samba share is described in the documentation here:

https://docs.docker.com/engine/storage/volumes/#create-cifssamba-volumes

I assume you read it, I just share it for anyone else.

You can’t use //IPADDRESS/FOLDER as a volume source directly. That is a special way to refer to a network filesystem, but normally on Linux that just means the root folder with an additional slash. In the volume definition, that is a device, not a path. It is just interpreted because the type is cifs, but there is no type defined in your last example.

You got an error message when you tried the right way, so that is what you need to figure out why. It looks like a DNS issue. Dd you just pass the name of the share? As the documentation suggests, it should be either an IP address or a domain name resolved by a DNS server.

NOTE: I fixed your post. Please, always check your message after sending it, because you will have fewer replies is any, when part of your message is missing.

Thank you for your answer! I solved my problem by giving the container SYS_ADMIN and DAC_READ_SEARCH capabilities nad then mounting the drive with cifs as i mentioned.

Ao if I understand it correctly, you didn’t create a docker volume using the cifs type, but ran a container and mounted the Samba share from inside the container?