Docker container user permission settings for SMB-mounted directory

To ensure the Docker container can read and write to an SMB-mounted directory, you need to properly set permissions on both:

  1. The SMB mount on the host system.
  2. The user inside the Docker container (usually by matching uid and gid).

โœ… 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 1000
  • gid=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 the docker 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, or www-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

TaskHow to Do It
Map files to correct UID/GIDUse uid=... and gid=... in mount -t cifs
Use correct container userUse --user UID:GID in docker run, or configure user in Dockerfile
Make sure mount is writableVerify permissions on SMB server, or use chmod/chown on mount path


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *