To ensure the Docker container can read and write to an SMB-mounted directory, you need to properly set permissions on both:
- The SMB mount on the host system.
- The user inside the Docker container (usually by matching
uid
andgid
).
โ Step-by-Step: Set Correct Permissions
๐งฑ 1. Mount the SMB Share with Correct UID/GID
Use mount -t cifs
with uid
and gid
options to set file ownership on the host.
Example:
sudo mount -t cifs //192.168.1.100/shared /mnt/smb \
-o username=myuser,password=mypass,uid=1000,gid=1000,vers=3.0
uid=1000
โ maps all files in the mount to user ID 1000gid=1000
โ maps group to group ID 1000- Check your Docker container user ID with:
docker exec -it mycontainer id
Example output:
uid=1000(node) gid=1000(node)
If your container uses UID 100, set uid=100
in the mount.
๐ณ 2. Match UID/GID Inside Docker
If your Docker image uses a specific user, you can:
- Use
--user
in thedocker run
command:
docker run --user 1000:1000 -v /mnt/smb:/data/smb-share my-n8n
- Or check the Dockerfile or entrypoint to see which user is used (some use
node
,n8n
, orwww-data
).
๐ 3. Adjust Mount Permissions (Optional)
If needed, you can also change permissions on the mount directory:
sudo chmod -R 770 /mnt/smb
sudo chown -R 1000:1000 /mnt/smb
But this only affects the local mount point; actual permissions are controlled by SMB share settings on the remote server.
โ Summary
Task | How to Do It |
---|---|
Map files to correct UID/GID | Use uid=... and gid=... in mount -t cifs |
Use correct container user | Use --user UID:GID in docker run , or configure user in Dockerfile |
Make sure mount is writable | Verify permissions on SMB server, or use chmod /chown on mount path |
Leave a Reply