知识库

个人知识管理

用户工具

站点工具


博客:用docker快速部署无密码samba服务器进行文件共享

用Docker快速部署无密码samba服务器进行文件共享

1. 下载docker镜像

docker pull dperson/samba

2. 启用docker容器

假设用户为dev

docker run -it --name samba -p 139:139 -p 445:445 -v /mnt/samba:/mount -d dperson/samba -u "dev;dev" -s "samba;/mount/;yes;no;yes;all;all;all" -w "WORKGROUP" -g "force user=dev" -g "guest account=dev"

我们把/mnt/samba目录作为共享目录,用户名密码由-u参数指定。

docker compose配置样例

version: '2'
 
services:
  samba:
    image: dperson/samba
    container_name: samba
    environment:
      TZ: 'Asia/Shanghai'
    networks:
      - default
    ports:
      - "137:137/udp"
      - "138:138/udp"
      - "139:139/tcp"
      - "445:445/tcp"
    read_only: true
    restart: unless-stopped
    stdin_open: true
    tty: true
    volumes:
      - /mnt/samba:/mount:z
    command: '-u "dev;dev" -s "samba;/mount/;yes;no;yes;all;all;all" -w "WORKGROUP" -g "force user=dev" -g "guest account=dev"'
 
networks:
  default:

详细参数

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

3. 在windows下访问

假设服务器IP 为 192.168.15.100 在文件管理器中输入如下url \\192.168.56.102

博客/用docker快速部署无密码samba服务器进行文件共享.txt · 最后更改: 2019/09/11 00:49 (外部编辑)