Home > OS >  Docker containers can't write inside cifs share
Docker containers can't write inside cifs share

Time:03-01

I have a docker compose for a media server i'm building using multiple containers, i want these containers to be able to R/W a cifs share mounted on host, after trying multiple ways i can't seem get them to write. here's the mounted share : /etc/fstab

//192.168.X.X/Media /mnt/Media cifs cache=loose,credentials=/root/.smbcrd,vers=3.0 0 0

and here's one of the multiple containers docker compose :

 emby:
image: linuxserver/emby
container_name: emby
environment:
  - PUID=998
  - PGID=100
  - TZ=Europe/Paris
  - UMASK_SET=022 #optional
volumes:
  - /mnt/Media/Configs/Emby:/config
  - /mnt/Media/Series:/data/series
  - /mnt/Media/Films:/data/movies
ports:
  - 8096:8096
  - 8920:8920 
restart: unless-stopped

I'm learning docker and i don't think mounting the cifs share inside every container is the solution,do i need to mount the share in volumes section of my docker compose ?,the share is a synology nas. can anyone help?

CodePudding user response:

CIFS Possibilities for Docker

Let Container mount (bad approach)

services:
  name:
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
    security_opt:
      - "apparmor=unconfined"

Dockerfile: ENTRYPOINT ["/bin/bash", "mount.sh" ]

mount.sh:

#!/bin/bash

mkdir /mnt/whatever
mount -v -t cifs -o username=xx,password=xx,vers=SMB-Version-Number,dir_mode=0744,file_mode=0744 //IP/Path /mnt/whatever

<start your container logic>

Bad approach due to very bad security, but in some use-cases could be helpful.

Let docker mount

services:
  name:
     volumes:
      - my_mount:/mnt/whatever

volumes:
  my_mount: 
    driver_opts:
      type: cifs
      o: username=xx,password=xx,vers=SMB-Version-Number
      device: //IP/Path

Let host mount

mount -t cifs -o username=xx,password=xx, \               
  uid=dockeruid,forceuid, \
  gid=dockergid,forcegid, \                  
  file_mode=744,dir_mode=744 //IP/Path /mnt/whatever   

run docker containers then with this user:

services:
  name:
    user: "dockeruid:dockergid"
    volumes:
      - /mnt/whatever:/mnt/whatever
  • Related