拉取镜像

docker pull dperson/samba:latest

挂载外接硬盘

参见这篇文章

配置并启动服务

下面的例子是将宿主机文件夹 /mnt/xzb (外挂了一个移动硬盘)映射到容器内的 /share 文件夹并共享这个文件夹,同时创建了一个叫mango的用户,并为上述文件夹赋予mango用户访问权限为可读可写并拥有管理权限。

注意,默认会开启回收站功能,也就是删除文件时不是真的删掉而是会移动到共享文件夹的.deleted目录中防止误删。所以如果想腾出空间删了一些大文件但发现空间没有释放那多半是在回收站里了。想彻底删除的话需要在服务器上进入这个目录手动删除(共享目录里面是看不到这个目录的)。如果觉得麻烦不想启用回收站的话可在下面的启动参数中添加一个-r即可。

docker run --name samba \
--detach \
--restart always \
--publish 139:139 --publish 445:445 \
--env USERID="0" \
--env GROUPID="0" \
--volume /mnt/xzb/:/share \
dperson/samba:latest \
-u "mango;YourPassword" \
-s "public;/share/;yes;no;no;mango;mango;mango;共享文件夹" \

参数说明

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

更多说明见官方Github

上面的参数修改可以在一开始docker run的时候指定(如本文上述的例子那样),也可以在容器启动后随时调用容器里的samba.sh修改或追加,比如想取消回收站的话执行下面这句即可。

docker exec -it samba samba.sh -r

有些命令是需要重启容器的,先停止再启动即可,如下

docker stop samba
docker start samba

删除共享目录

docker image提供的命令行没有提供删除共享目录的命令。可以自己进入容器修改以下配置文件

/etc/samba/smb.conf

如有需要,可以同时安装远程下载bt的服务搭建自己的下载机

很简单,一句话搞定。

docker run -d --restart always -p 3000:3000 -v /mnt/xzb/cloud-torrent/:/downloads jpillora/cloud-torrent 

版权属于:芒果爱吃胡萝卜

本文链接:http://blog.mangolovecarrot.net/2021/06/06/328

转载时须注明出处及本声明

Last modification:June 6th, 2021 at 11:57 pm