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
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.
What is recommended to use in this case: CIFS or NFS?
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.
I think this solves my problem (trying to get a drive shared by Samba in a Pi available to a docker instance in Windows) but I can’t get docker to mount it and I can’t find proper documentation about it. (I’m super new to this so very likely I just don’t understand what’s relevant)
Is the username/password mandatory? My share does not have one nor have I created a user for it.
How does one access the share in the compose file?
The user id and group id are numeric ids, not names. They must match those, the container uses to run the main process. Check the Docker HUB description of the used image whether it describes which UID:GID it uses, or check if it allows setting them as environment variables (some images do, most don’t).
NOTE: a volume declaration is immutable! Once created, changes to the compose file are not reflected back to the configuration of the volume. In order to update the volume configuration, you must stop your compose project, delete the volume, then re-deploy the compose project.
Thanks for the super quick reply!
I thought the uid/gid were the ones set in Pi in /etc/fstab.
I will try to find them for the image, applied the changes you mentioned and tried with 1000/1000, no dice.
Also appreciate the tip on killing the volume after stopping the container.
If after getting the proper uid/gid still doesnt work I’ll look into adding a username and pass.
Nope. Every volume must be configured from the perspective and needs of a particular container.
You can find the UID and GID required by a container by running these commands:
# find user name that runs the main process in the output
docker exec -u 0 {container id or name } ps
# find uid/gid of the user
docker exec -u 0 {container id or name } id {USER}
Hi - I have a related question here where I have successfully added the volumes in docker for my smb shares but was wondering if you can then specify a folder within that volume??
For example, I have a volume that points to my “media” share - but inside that shared drive are separate folders for TV, Movies & Music. Do I have to set up these folders as their own volumes? Or can I somehow point to these folders inside these volumes? Would make more sense and be much cleaner to have one volume rather than 3 but I can’t seem to find a way to make this happen
It would. But it is not possible with Docker… Though, Kubernetes volume mounts support it. I guess it’s easier to raise a feature request in the issues of the compose specification Github project.