Samba 是 SMB/CIFS 網絡協議的從新實現, 它做爲 NFS 的補充使得在 Linux、OS/二、DOS 和 Windows 系統中進行文件共享、打印機共享更容易實現。SMB協議是客戶機/服務器型協議,客戶機經過該協議能夠訪問服務器上的共享文件系統、打印機及其餘資源。經過設置「NetBIOS over TCP/IP」使得Samba不但能與局域網絡主機分享資源,還能與全世界的電腦分享資源。linux
這裏經過使用docker鏡像的方式來簡化samba的安裝, 來實現不一樣系統之間共享目錄。git
運行dockergithub
sudo docker run -it -p 139:139 -p 445:445 -d dperson/samba
若是要使用本地存儲,則能夠:docker
sudo docker run -it --name samba -p 139:139 -p 445:445 \ -v /path/to/directory:/mount \ -d dperson/samba
配置參數:服務器
docker run -it --rm dperson/samba -h Usage: samba.sh [-opt] [command] Options (fields in '[]' are optional, '<>' are required): -h This help -c "<from:to>" setup character mapping for file/directory names required arg: "<from:to>" character mappings separated by ',' -g "<parameter>" Provide global option for smb.conf required arg: "<parameter>" - IE: -g "log level = 2" -i "<path>" Import smbpassword required arg: "<path>" - full file path in container -n Start the 'nmbd' daemon to advertise the shares -p Set ownership and permissions on the shares -r Disable recycle bin for shares -S Disable SMB2 minimum version -s "<name;/path>[;browse;readonly;guest;users;admins;writelist;comment]" Configure a share required arg: "<name>;</path>" <name> is how it's called for clients <path> path to share NOTE: for the default value, just leave blank [browsable] default:'yes' or 'no' [readonly] default:'yes' or 'no' [guest] allowed default:'yes' or 'no' [users] allowed default:'all' or list of allowed users [admins] allowed default:'none' or list of admin users [writelist] list of users that can write to a RO share [comment] description of share -u "<username;password>[;ID;group]" Add a user required arg: "<username>;<passwd>" <username> for user <password> for user [ID] for user [group] for user -w "<workgroup>" Configure the workgroup (domain) samba should use required arg: "<workgroup>" <workgroup> for samba -W Allow access wide symbolic links -I Add an include option at the end of the smb.conf required arg: "<include file path>" <include file path> in the container, e.g. a bind mount The 'command' (if provided and valid) will be run instead of samba
示例網絡
如今要將目錄xw_share, 經過139和445端口進行共享, 並建立用戶xw(密碼爲:overkill),禁用匿名用戶訪問,而且容許用戶xw讀寫操做,能夠以下設置:app
docker run -it --name samba -p 139:139 -p 445:445 \ -v $PWD/nl_share:/mount -d dperson/samba -u "xw;overkill" -s "xw;/mount/;yes;no;no;all;xw;xw"
參考:dom