+README
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
quackerd 2021-02-19 19:27:46 -05:00
parent ff23651cf2
commit 0d77a93919
Signed by: d
GPG Key ID: F73412644EDE357A
3 changed files with 43 additions and 15 deletions

View File

@ -1,3 +1,30 @@
# docker-samba
Samba in Docker
[![Build Status](https://ci.quacker.org/api/badges/d/docker-samba/status.svg)](https://ci.quacker.org/d/docker-samba)
## What is this?
This is Samba server in Docker. The image is designed for flexbility and maintainability. You are expected to supply your own smb.conf and user/group configs. You also need to maintain the proper permissions for shared folders, which usually only need to be done correctly once at the beginning.
TL;DR: if you are familiar with Samba configuration, this image is for you.
## Usage
### Volumes
- `/samba/smb.conf`: the Samba configuration file that the container uses.
- `/samba/[share]`: please map your Samba share folders to `/samba/` in the container.
### Environment Variables
- `GROUPS`: group configurations. Format: `[group name],[group id]`. Connect multiple group configs with `;`.
- `USERS`: user configurations. Format: `[username],[user id],[samba password],[additional group names*]`. `*`: this option is optional and you can specify multiple groups using `,` as separator.
- `SMBD_ARGS`: additional parameters for `smbd`. E.g. `-d 2` which enables debug output.
### docker-compose
Please see the `example` folder.
## Updating
`docker-compose pull && docker-compose down && docker-compose up -d`
## Troubleshooting
Add `-d 2` to `SMBD_ARGS` for samba debug output.
Q: I can't access mounted config file or directories?
A: Are you running SELinux? If so you need to set the correct tag on mounted volumes `chcon -t svirt_sandbox_file_t [your file/folder]`

View File

@ -19,8 +19,8 @@ def main():
if (len(elements) != 2):
print("Skipping invalid group config string \"" + group + "\"")
continue
gid = elements[1]
gname = elements[0]
gid = elements[1].strip()
gname = elements[0].strip()
cmd = "addgroup -g" + shlex.quote(gid) + " " + shlex.quote(gname)
print(cmd)
subprocess.check_call("addgroup -g" + shlex.quote(gid) + " " + shlex.quote(gname), shell=True, stdout=subprocess.DEVNULL)
@ -29,20 +29,21 @@ def main():
# username,uid,password,[group]
for user in users:
elements = user.split(',')
if (len(elements) != 3 and len(elements) != 4):
if (len(elements) < 3):
print("Skipping invalid user config string \"" + user + "\"")
continue
uname = elements[0]
uid = elements[1]
passwd = elements[2]
uname = elements[0].strip()
uid = elements[1].strip()
passwd = elements[2].strip()
cmd = "adduser -D -H -u " + shlex.quote(uid) + " " + shlex.quote(uname)
print(cmd)
subprocess.check_call(cmd, shell=True, stdout=subprocess.DEVNULL)
if (len(elements) == 4):
gname = elements[3]
cmd = "addgroup " + shlex.quote(uname) + " " + shlex.quote(gname)
print(cmd)
subprocess.check_call(cmd, shell=True, stdout=subprocess.DEVNULL)
if (len(elements) > 3):
for i in range(3, len(elements)):
gname = elements[i].strip()
cmd = "addgroup " + shlex.quote(uname) + " " + shlex.quote(gname)
print(cmd)
subprocess.check_call(cmd, shell=True, stdout=subprocess.DEVNULL)
# set passwd
cmd = "echo -ne \"" + shlex.quote(passwd) + "\\n" + shlex.quote(passwd) + "\\n\" | smbpasswd -a -U " + shlex.quote(uname)
print(cmd)

View File

@ -16,10 +16,10 @@ services:
- "445:445/tcp"
environment:
# create two users: "user1" with uid 1000, smb password password1 and add user1 to group1
# "user2" with uid 1001, smb password password2 and add user2 to group1
- "USERS=user1,1000,password1,group1;user2,1001,password2,group1"
# "user2" with uid 1001, smb password password2 and add user2 to group1 and group2
- "USERS=user1,1000,password1,group1;user2,1001,password2,group1,group2"
# create a group with group name "group1" and gid 2000
- "GROUPS=group1,2000"
- "GROUPS=group1,2000;group2,2001"
# launch smbd with extra parameters => -d 2 means log level = 2
- "SMBD_ARGS=-d 2"
restart: unless-stopped