拉取镜像

docker pull  dperson/samba

创建本地共享文件夹

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

连接挂载成功,如图

docker搭建samba服务smb网络磁盘共享_docker samba

-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  写入的用户

docker搭建samba服务smb网络磁盘共享_docker samba_02

用户管理

添加samba用户前系统用户必须存在,系统用户没有的不能添加

系统用户文件:    /etc/password
samba用户文件:    /etc/samba/smbpassword

添加系统用户

useradd [参数] <用户名>

useradd username //新增
passwd username //设置密码 用于系统登录,不设也可以使用samba

添加samba用户

1)添加用户



  1. [root@localhost ~]# smbpasswd -a username //添加用户,设置密码
  2. New SMB password:
  3. Retype new SMB password:
  4. Added user username.

2)修改用户密码

  1. [root@localhost ~]#smbpasswd username //修改用户密码
  2. New SMB password:
  3. 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

显示帮助信息