I found this when looking for something similar but see that though it's old it's missing some key information, possibly because they weren't available at the time
The CIFS storage is, I believe, only for when you are connecting to a Windows System as I do not believe it is used by Linux at all.
EDIT: It looks like Docker considered SMB(Samba) to be CIFS Volumes
This same thing can be done with NFS, which is less secure, but is supported by almost everything.
you can create an NFS volume in a similar way to the CIFS one, just with a few changes. I'll list both so they can be seen side by side
When using NFS on WSL2 you 1st need to install the NFS service into the Linux Host OS. I believe CIFS requires a similar one, but as I don't use it I'm not certain.
EDIT: It looks like WSL2 Docker at least for SMB(Samba), CIFS Volumes either don't require any dependencies or I already have them, possibly the same one I install for NFS bellow
In my case the Host OS is Ubuntu, but you should be able to find the appropriate one by finding your system's equivalent for nfs-common
installation
sudo apt update
sudo apt install nfs-common
That's it. That will install the service so NFS works on Docker (It took me forever to realize that was the problem since it doesn't seem to be mentioned as needed anywhere)
On the network device you need to have set NFS permissions for the NFS folder, in my case this would be done at the folder
folder with the mount then being to a folder inside it. That's fine. In my case the NAS that is my server mounts to #IP#/volume1/folder
, within the NAS I never see the volume1
in the directory structure, but that full path to the shared folder is shown in the settings page when I set the NFS permissions. I'm not including the volume1
part as your system will likely be different & you want the FULL PATH after the IP (use the IP as the numbers NOT the HostName), according to your NFS share, whatever it may be.
- The
nolock
option is often needed but may not be on your system. It just disables the ability to "lock" files.
- The
soft
option means that if the system cannot connect to the mount directory it will not hang. If you need it to only work if the mount is there you can change this to hard
instead.
- The
rw
(read/write) option is for Read/Write, ro
(read-only) would be for Read Only
As I don't personally use the CIFS volume the options set are just ones in the examples I found, whether they are necessary for you will need to be looked into.
- The
username
& password
are required & must be included for CIFS
uid
& gid
are Linux user & group settings & should be set, I believe, to what your container needs as Windows doesn't use them to my knowledge
file_mode=0777
& dir_mode=0777
are Linux Read/Write Permissions essentially like chmod 0777
giving anything that can access the file Read/Write/Execute permissions (More info Link #4) & this should also be for the Docker Container not the CIFS host
noexec
has to do with execution permissions but I don't think actually function here, nosuid
limits it's ability to access files that are specific to a specific user ID & shouldn't need to be removed unless you know you need it to be, as it's a protection, nosetuids
means that it won't set UID & GUID for newly created files, nodev
means no access to/creation of devices on the mount point, vers=1.0
I think is a fallback for compatibility, I personally would not include it unless there is a problem or it doesn't work without it
In these examples I'm mounting //NET.WORK.DRIVE.IP/folder/on/addr/device
to a volume named "my-docker-volume
" in Read/Write mode. The CIFS volume is using the user supercool
with password noboDyCanGue55
NFS from the CLI
docker volume create --driver local --opt type=nfs --opt o=addr=NET.WORK.DRIVE.IP,nolock,rw,soft --opt device=:/folder/on/addr/device my-docker-volume
CIFS from CLI (May not work if Docker is installed on a system other than Windows, will only connect to an IP on a Windows system)
docker volume create --driver local --opt type=cifs --opt o=user=supercool,password=noboDyCanGue55,rw --opt device=//NET.WORK.DRIVE.IP/folder/on/addr/device my-docker-volume
This can also be done within Docker Compose or Portainer.
When you do it there, you will need to add a Volumes:
at the bottom of the compose file, with no indent, on the same level as services:
In this example I am mounting the volumes
my-nfs-volume
from //10.11.12.13/folder/on/NFS/device
to "my-nfs-volume
" in Read/Write mode & mounting that in the container to /nfs
my-cifs-volume
from //10.11.12.14/folder/on/CIFS/device
with permissions from user supercool
with password noboDyCanGue55
to "my-cifs-volume
" in Read/Write mode & mounting that in the container to /cifs
version: '3'
services:
great-container:
image: imso/awesome/youknow:latest
container_name: totally_awesome
environment:
- PUID=1000
- PGID=1000
ports:
- 1234:5432
volumes:
- my-nfs-volume:/nfs
- my-cifs-volume:/cifs
volumes:
my-nfs-volume:
name: my-nfs-volume
driver_opts:
type: "nfs"
o: "addr=10.11.12.13,nolock,rw,soft"
device: ":/folder/on/NFS/device"
my-cifs-volume:
driver_opts:
type: "cifs"
o: "username=supercool,password=noboDyCanGue55,uid=1000,gid=1000,file_mode=0777,dir_mode=0777,noexec,nosuid,nosetuids,nodev,vers=1.0"
device: "//10.11.12.14/folder/on/CIFS/device/"
More details can be found here:
- https://docs.docker.com/engine/reference/commandline/volume_create/
- https://www.thegeekdiary.com/common-nfs-mount-options-in-linux/
- https://web.mit.edu/rhel-doc/5/RHEL-5-manual/Deployment_Guide-en-US/s1-nfs-client-config-options.html
- https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/