docker搭建samba服務smb網絡磁盤共享方式
拉取鏡像
docker pull dperson/samba
創(chuàng)建本地共享文件夾
mkdir /home/share
運行鏡像
docker run -it --name samba -p 139:139 -p 445:445 -v /home/share:/mount -d dperson/samba -u "user;123456" -s "share;/mount/;yes;no;no;all;user;user"
-u 用戶名:密碼, 多個用戶多次使用-u
連接測試
連接到服務器 ,地址填 smb://192.168.100.100
連接掛載成功,如圖:

-s“<name;/path>[;瀏覽;只讀;來賓;用戶;管理員;寫入列表;注釋]”
配置共享
必需的參數:“<name>;</path>”
- <name>是對客戶的稱呼
- <path>共享路徑
注意:對于默認值,請留空
- [可瀏覽]默認值:“是”或“否”
- [只讀]默認值:“是”或“否”
- [來賓]允許的默認值:“是”或“否”
對于用戶名,下面的列表用“,”注意:下面的列表用“,”分隔
- [用戶]允許的默認值:“所有”或允許的用戶列表
- [管理員]允許的默認值:“無”或管理員用戶列表
- [要寫入的用戶列表]
其他命令解釋
[root@localhost share]# 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 "<section;parameter>" Provide generic section option for smb.conf
required arg: "<section>" - IE: "share"
required arg: "<parameter>" - IE: "log level = 2"
-g "<parameter>" Provide global option for smb.conf
required arg: "<parameter>" - IE: "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'
NOTE: for user lists below, usernames are separated by ','
[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;GID]" Add a user
required arg: "<username>;<passwd>"
<username> for user
<password> for user
[ID] for user
[group] for user
[GID] for group
-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運行后添加用戶可進入容器里面添加,
docker exec -it samba /bin/bash
配置文件
vi /etc/samba/sms.conf
[share] path = /mount/ browsable = yes read only = no guest ok = no ////匿名用戶不允許訪問 veto files = /.apdisk/.DS_Store/.TemporaryItems/.Trashes/desktop.ini/ehthumbs.db/Network Trash Folder/Temporary Items/Thumbs.db/ delete veto files = yes admin users = user01 //管理的用戶 write list = user01 ////寫入的用戶

用戶管理
添加samba用戶前系統(tǒng)用戶必須存在,系統(tǒng)用戶沒有的不能添加
- 系統(tǒng)用戶文件:/etc/password
- samba用戶文件:/etc/samba/smbpassword
添加系統(tǒng)用戶
useradd [參數] <用戶名>
useradd username //新增 passwd username //設置密碼 用于系統(tǒng)登錄,不設也可以使用samba
添加samba用戶
1) 添加用戶
[root@localhost ~]# smbpasswd -a username //添加用戶,設置密碼 New SMB password: Retype new SMB password: Added user username.
2) 修改用戶密碼
[root@localhost ~]#smbpasswd username //修改用戶密碼 New SMB password: Retype new SMB password:
smbpasswd命令
smbpasswd指令可以用來修改samba用戶的的密碼,該指令不僅可以修改本地samba服務器的用戶密碼,還可以修改遠程samba服務器的用戶密
1、語法
smbpasswd [選項] username
2、選項列表
選項 | 說明 |
-a | 添加用戶到samba服務器 |
-c | 指定配置文件smb.conf的位置 |
-x | 刪除用戶 |
-d | 停止使用指定的用戶 |
-e | 激活暫停的用戶 |
-D | 設置調試級別0~10 |
-n | 指定用戶名為空密碼 |
-r | 指定遠程smb服務器上的用戶密碼 |
-U | 指定用戶名,只和-r配合使用 |
-h | 顯示幫助信息 |
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Docker核心技術之Dockerfile指令詳解及綜合案例
Dockerfile是一個用來構建鏡像的文本文件, 文本內容包含了一條條構建鏡像所需的指令和說明,這篇文章主要介紹了Docker核心技術之Dockerfile指令詳解及綜合案例的相關資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2026-05-05
docker的WARNING:bridge-nf-call-iptables is disabled
這篇文章主要介紹了docker的WARNING:bridge-nf-call-iptables is disabled的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
新版本Docker?Desktop自定義安裝路徑和下載鏡像地址路徑修改方法
Docker是一個開源的應用容器引擎,讓開發(fā)者可以打包他們的應用以及依賴包到一個可移植的鏡像中,這篇文章主要介紹了新版本Docker?Desktop自定義安裝路徑和下載鏡像地址路徑修改方法的相關資料,需要的朋友可以參考下2025-12-12

