侧边栏壁纸
博主头像
前端小菜鸟 博主等级

聪明是一种天赋,而善良是一种选择。

  • 累计撰写 37 篇文章
  • 累计创建 24 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Docker搭建smb共享服务器

fanfan
2024-06-22 / 0 评论 / 0 点赞 / 146 阅读 / 0 字
温馨提示:
本文最后更新于2024-06-22,若内容或图片失效,请留言反馈。 部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

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

docker-compose

version: '3.4'

services:
  samba:
    image: dperson/samba
    environment:
      TZ: 'EST5EDT'
    networks:
      - default
    ports:
      - "137:137/udp"
      - "138:138/udp"
      - "139:139/tcp"
      - "445:445/tcp"
    read_only: true
    tmpfs:
      - /tmp
    restart: unless-stopped
    stdin_open: true
    tty: true
    volumes:
      - /mnt:/mnt:z
      - /mnt2:/mnt2:z
    command: '-s "Mount;/mnt" -s "Bobs Volume;/mnt2;yes;no;no;bob" -u "bob;bobspasswd" -p'

networks:
  default:

0
博主关闭了所有页面的评论