首页 > 其他分享 >Docker搭建smb共享服务器

Docker搭建smb共享服务器

时间:2024-03-05 19:59:26浏览次数:27  
标签:Samba share smb samba user 服务器 Docker yes

Docker搭建smb共享服务器

快速启动

docker run -it --name samba \
        -p 139:139 \
        -p 445:445 \
        -v /path/to/share:/share_dir \
        -d dperson/samba \
        -u "username;password" \
        -s "share_name;/share_dir/;yes;no;yes;all;username;username"

执行上述命令首先拉取dperson/samba​镜像,随后创建一个smb容器,将宿主机/path/to/share​目录进行共享,共享盘名称为share_name​。

  • -u​:创建用户username/password​,需要多个目录是可以添加多个-u​参数

  • -s​:配置共享目录信息,格式为-s "<name;/path>[;browse;readonly;guest;users;admins;writelist;comment]"

    • browse​:是否可以被发现,如Windows​中的网络​, yes​/no
    • readonly​:共享盘是否为只读​, yes​/no
    • guest​:是否允许访客, yes​/no
    • users​:允许的用户,默认为all​,或者使用,​分割的用户列表
    • admins​:管理员用户,默认为none​,或者使用,​分割的用户列表
    • writelist​:对于只读​盘,可以写的用户列表
    • comment​:共享盘的描述

容器详细使用方法

sudo 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 values, 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

进阶用法

自定义smb.conf​配置文件

通过在容器创建时挂载smb.conf​文件,来设置复杂的smb服务配置,详细设置可以查看官方文档,上述docker run创建的容器的配置文件如下所示

# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba, 
# read the Samba-HOWTO-Collection. This may be obtained from:
#  http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the 
# Samba-Guide which is generated daily and can be downloaded from: 
#  http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# Any line which starts with a ; (semi-colon) or a # (hash) 
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not made any basic syntactic errors. 
#
#=====================<span style="font-weight: bold;" class="mark"> Global Settings </span>===================================
[global]

# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
   workgroup = MYGROUP

# server string is the equivalent of the NT Description field
   server string = Samba Server

# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller".
#
# Most people will want "standalone server" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
   server role = standalone server

# This option is important for security. It allows you to restrict
# connections to machines which are on your local network. The
# following example restricts access to two C class networks and
# the "loopback" interface. For more examples of the syntax see
# the smb.conf man page
;   hosts allow = 192.168.1. 192.168.2. 127.

# Uncomment this if you want a guest account, you must add this to /etc/passwd
# otherwise the user "nobody" is used
;  guest account = pcguest

# this tells Samba to use a separate log file for each machine
# that connects
   log file = /dev/stdout

# Put a capping on the size of the log files (in Kb).
   max log size = 50

# Specifies the Kerberos or Active Directory realm the host is part of
;   realm = MY_REALM

# Backend to store user information in. New installations should 
# use either tdbsam or ldapsam. smbpasswd is available for backwards 
# compatibility. tdbsam requires no further configuration.
;   passdb backend = tdbsam

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting.
# Note: Consider carefully the location in the configuration file of
#       this line.  The included file is read at that point.
;   include = /usr/local/samba/lib/smb.conf.%m

# Configure Samba to use multiple interfaces
# If you have multiple network interfaces then you must list them
# here. See the man page for details.
;   interfaces = 192.168.12.2/24 192.168.13.2/24 

# Where to store roving profiles (only for Win95 and WinNT)
#        %L substitutes for this servers netbios name, %U is username
#        You must uncomment the [Profiles] share below
;   logon path = \\%L\Profiles\%U

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
;   wins support = yes

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
#       Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
;   wins server = w.x.y.z

# WINS Proxy - Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one  WINS Server on the network. The default is NO.
;   wins proxy = yes

# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The default is NO.
   dns proxy = no 

# These scripts are used on a domain controller or stand-alone 
# machine to add or delete corresponding unix accounts
;  add user script = /usr/sbin/useradd %u
;  add group script = /usr/sbin/groupadd %g
;  add machine script = /usr/sbin/adduser -n -g machines -c Machine -d /dev/null -s /bin/false %u
;  delete user script = /usr/sbin/userdel %u
;  delete user from group script = /usr/sbin/deluser %u %g
;  delete group script = /usr/sbin/groupdel %g


   pam password change = yes
   map to guest = bad user
   usershare allow guests = yes
   create mask = 0664
   force create mode = 0664
   directory mask = 0775
   force directory mode = 0775
   force user = smbuser
   force group = smb
   follow symlinks = yes
   load printers = no
   printing = bsd
   printcap name = /dev/null
   disable spoolss = yes
   strict locking = no
   aio read size = 0
   aio write size = 0
   vfs objects = catia fruit recycle streams_xattr
   recycle:keeptree = yes
   recycle:maxsize = 0
   recycle:repository = .deleted
   recycle:versions = yes

   # Security
   client ipc max protocol = SMB3
   client ipc min protocol = SMB2_10
   client max protocol = SMB3
   client min protocol = SMB2_10
   server max protocol = SMB3
   server min protocol = SMB2_10

   # Time Machine
   fruit:delete_empty_adfiles = yes
   fruit:time machine = yes
   fruit:veto_appledouble = no
   fruit:wipe_intentionally_left_blank_rfork = yes

[share]
   path = /share_dir/
   browsable = yes
   read only = no
   guest ok = yes
   veto files = /.apdisk/.DS_Store/.TemporaryItems/.Trashes/desktop.ini/ehthumbs.db/Network Trash Folder/Temporary Items/Thumbs.db/
   delete veto files = yes
   admin users = username
   write list = username

参考资料

dperson/samba docker hub主页

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

smb.conf官方文档

标签:Samba,share,smb,samba,user,服务器,Docker,yes
From: https://www.cnblogs.com/Biiigwang/p/18054755/docker-builds-smb-shared-server-zabaqf

相关文章

  • SSRF服务器端请求伪造
    SSRF服务器端请求伪造凡是发起网络请求的地方,就有可能涉及ssrf1.SSRF漏洞定义:SSRF(Server-sideRequestForge)服务器端请求伪造,由于服务端提供了从其他服务器应用获取数据的功能,但没有对地址和协议等做过滤和限制。使得攻击者可以利用存在缺陷的web应用作为代理,攻击其远程和本地......
  • Docker安装Clickhouse
    博客园首页新随笔联系管理订阅随笔-71 文章-1 评论-0 阅读-55274 Docker安装Clickhouse https://clickhouse.com/clickhouse官网https://hub.docker.com/r/clickhouse/clickhouse-server/此为Docker安装Clickhouse官网此为按照命......
  • Docker数据持久化挂载与卷(三)
    前言前面学了Docker基本的使用和通信,但是由于容器的生命周期是短暂的,当容器被删除后,容器内的数据也会一并删除。为了保存数据,我们可以使用DockerVolume将数据存储在宿主机上,从而实现数据的持久化。一、数据修改一般来看配置、数据等重要数据都需要变动,所以数据修改也......
  • 无人直播,云SRS,Docker一键搭建安装教程
    如果有服务器并已经安装Docker,可以直接从第四步开始。第一步:选购轻量应用服务器并安装Ubuntu22或者20系统。境外服务器以香港和日本、新加坡为佳。24小时无人直播流量需求比较大,请按照视频码率自己算好,超出后流量非常昂贵。【以视频码率5000为例:5000/8/1024*3600*24*31/1024/102......
  • .Net项目部署到Docker
    .Net项目部署到Docker环境linuxdocker.Net7步骤编写Dockerfile上传项目文件到linux运行项目文件到docker一、设置项目端口在Program.cs文件设置端口builder.WebHost.UseUrls("http://*:1040");//单个设置二、添加Dockerfile文件点击Docker支持,会弹框选择lin......
  • 记一次部署vika源码以及安装Falsk框架到linux服务器
    前言接受到需求,需要把python项目vika的源码修改部分内容后,部署到服务器,然后再安装一个python的快速开发框架Falsk。部署vika1.什么是vika?Vika PythonSDK是对维格表FusionAPI的官方封装,提供类似DjangoORM风格的API。2.下载源码前往源码地址(https://github.com/vikadat......
  • Windows环境下Pytorch项目搭建在Docker中运行
    Windows环境下Pytorch项目搭建在Docker中运行1.安装windows版本的Docker​ 网上已有诸多博客教程,这里就不再赘述。2.搭建本地Pytorch环境​ 搭建本地Pytorch环境的方式我使用了两种方式,推荐使用第一种。​ 第一种:​ (1)在dockerhub中(https://hub.docker.com),找到自己版本......
  • Docker多容器和通信搭建(二)
    前言前面介绍了Docker容器的基础服务搭建,对于Docker容器来说一般都是多个容器项目运行在服务器上。所以这篇主要讲述多容器之间的交互,以及宿主与容器之间的交互问题。一、部署多容器接着以Nginx为例,部署多个Nginx容器进行测试。~]#dockerrun-d--namenginx-p80......
  • 配置 HTTPERR 错误日志记录,不断增长会沾满C盘导致服务器停机
    配置HTTPAPI错误日志记录HTTP\Parameters键下的三个注册表值控制HTTPAPI错误日志记录。这些密钥位于注册表项中: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters。 备注在Windows操作系统的更高版本中,配置值的位置和形式可能会更改。......
  • SMB(Server Message Block)协议配置信息的位置
    %SystemRoot%\system32\srvsvc.dll%SystemRoot%\System32\svchost.exe-ksmbsvcs%systemroot%\system32\wkssvc.dll%SystemRoot%\System32\svchost.exe-kNetworkService-p\Device\NetBT_Tcpip6_{93123211-9629-4E04-82F0-EA2E4F221468}\Device\Tcpip6_{93......