An open API service indexing awesome lists of open source software.

https://github.com/adrianmusante/docker-samba

An updated version of the Samba Docker image, originally developed by dperson/samba
https://github.com/adrianmusante/docker-samba

docker samba samba-server

Last synced: 5 months ago
JSON representation

An updated version of the Samba Docker image, originally developed by dperson/samba

Awesome Lists containing this project

README

          

[![logo](https://github.com/adrianmusante/docker-samba/assets/38815440/f72b6c2a-637d-4a66-bbb9-7db4cbde3bb4)](https://www.samba.org)

# Samba

An updated version of the Samba Docker image, originally developed by [dperson/samba](https://github.com/dperson/samba).

## What is Samba?

Since 1992, Samba has provided secure, stable and fast file and print services
for all clients using the SMB/CIFS protocol, such as all versions of DOS and
Windows, OS/2, Linux and many others.

## Docker registry

The recommended way to get Samba Docker Image is to pull the prebuilt image from the [Docker Hub Registry](https://hub.docker.com/r/adrianmusante/samba).

To use a specific version, you can pull a versioned tag. You can view the [list of available versions](https://hub.docker.com/r/adrianmusante/samba/tags/) in the Docker Hub Registry.

- [`4`, `4.22`, `latest` (samba/Dockerfile)](https://github.com/adrianmusante/docker-samba/blob/main/samba/Dockerfile)

## Configuration

### How to use this image

By default there are no shares configured, additional ones can be added.

docker run -it -p 139:139 -p 445:445 -d adrianmusante/samba -p

OR set local storage:

docker run -it --name samba -p 139:139 -p 445:445 \
-v /path/to/directory:/mount \
-d adrianmusante/samba -p

### Command options

When starting the container you can pass options to the `samba` command.
For see the available options run:

$ docker run -it --rm adrianmusante/samba -h
Usage: samba [-opt] [command]
Options (fields in '[]' are optional, '<>' are required):
-h This help
-c "" setup character mapping for file/directory names
required arg: "" character mappings separated by ','
-G "" Provide generic section option for smb.conf
required arg: "" - IE: "share"
required arg: "" - IE: "log level = 2"
-g "" Provide global option for smb.conf
required arg: "" - IE: "log level = 2"
-i "" Import smbpassword
required arg: "" - 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 "[;browse;readonly;guest;users;admins;writelist;comment]"
Configure a share
required arg: ";"
is how it's called for clients
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 "[;ID;group;GID]" Add a user
required arg: ";"
for user
for user
[ID] for user
[group] for user
[GID] for group
-w "" Configure the workgroup (domain) samba should use
required arg: ""
for samba
-W Allow access wide symbolic links
-I Add an include option at the end of the smb.conf
required arg: ""
in the container, e.g. a bind mount

The 'command' (if provided and valid) will be run instead of samba

### Environment variables

The container can also be configured with environment variables.
When you start the Samba image, you can adjust the configuration of the instance by passing one or more environment
variables either on the docker-compose file or on the `docker run` command line.
If you want to add a new environment variable:

- `PUID`: Set the UID for the samba server's default user (smbuser)
- `PGID`: Set the GID for the samba server's default user (smbuser)
- `TZ`: Set a timezone, IE `EST5EDT`
- `SAMBA_DEBUG`: Verbose mode. Default: **false**
- `SAMBA_LOG_LEVEL`: Set the log level (0-10). Higher levels generate more detailed logs, but should only be used for debugging. The default is 0 (only critical errors and warnings) but if `SAMBA_DEBUG` is enabled the default value is 3.
- `SAMBA_CHARMAP`: As above, configure character mapping
- `SAMBA_GENERIC`: As above, configure a generic section option (See NOTE3 below)
- `SAMBA_GLOBAL`: As above, configure a global option (See NOTE3 below)
- `SAMBA_IMPORT`: As above, import a smbpassword file
- `SAMBA_NMBD`: As above, enable nmbd
- `SAMBA_PERMISSIONS`: As above, set file permissions on all shares
- `SAMBA_RECYCLE`: As above, disable recycle bin
- `SAMBA_SHARE`: As above, setup a share (See NOTE3 below)
- `SAMBA_SMB`: As above, disable SMB2 minimum version
- `SAMBA_USER`: As above, setup a user (See NOTE3 below)
- `SAMBA_WIDELINKS`: As above, allow access wide symbolic links
- `SAMBA_WORKGROUP`: As above, set workgroup
- `SAMBA_INCLUDE`: As above, add a smb.conf include

**NOTE**: if you enable nmbd (via `-n` or the `SAMBA_NMBD` environment variable), you
will also want to expose port 137 and 138 with `-p 137:137/udp -p 138:138/udp`.

**NOTE2**: there are reports that `-n` and `SAMBA_NMBD` only work if you have the
container configured to use the hosts network stack.

**NOTE3**: optionally supports additional variables starting with the same name,
IE `SAMBA_SHARE` also will work for `SAMBA_SHARE2`, `SAMBA_SHARE3`... `SAMBA_SHAREx`, etc.

## Examples

Any of the commands can be run at creation with `docker run` or later with
`docker exec -it samba samba` (as of version 1.3 of docker).

### Setting the Timezone

docker run -it -e TZ=EST5EDT -p 139:139 -p 445:445 -d adrianmusante/samba -p

### Start an instance creating users and shares:

docker run -it -p 139:139 -p 445:445 -d adrianmusante/samba -p \
-u "example1;badpass" \
-u "example2;badpass" \
-s "public;/share" \
-s "users;/srv;no;no;no;example1,example2" \
-s "example1 private share;/example1;no;no;no;example1" \
-s "example2 private share;/example2;no;no;no;example2"

### Start an instance without NetBIOS:

docker run -it -e SAMBA_GLOBAL="disable netbios = yes" -e SAMBA_GLOBAL_1="netbios name = $(hostname)" \
-p 445:445 -d adrianmusante/samba -p \
-u "example1;badpass" \
-u "example2;badpass" \
-s "public;/share" \
-s "users;/srv;no;no;no;example1,example2" \
-s "example1 private share;/example1;no;no;no;example1" \
-s "example2 private share;/example2;no;no;no;example2"

## User Feedback

### Troubleshooting

* You get the error `Access is denied` (or similar) on the client and/or see
`change_to_user_internal: chdir_current_service() failed!` in the container
logs.

Add the `-p` option to the end of your options to the container, or set the
`SAMBA_PERMISSIONS` environment variable.

docker run -it --name samba -p 139:139 -p 445:445 \
-v /path/to/directory:/mount \
-d adrianmusante/samba -p

If changing the permissions of your files is not possible in your setup you
can instead set the environment variables `PUID` and `PGID` to the
values of the owner of your files.

* High memory usage by samba. Multiple people have reported high memory usage
that's never freed by the samba processes. Recommended work around below:

Add the `-m 512m` option to docker run command, or `mem_limit:` in
docker_compose.yml files, IE:

docker run -it --name samba -m 512m -p 139:139 -p 445:445 \
-v /path/to/directory:/mount \
-d adrianmusante/samba -p

* Attempting to connect with the `smbclient` command-line tool: By default, Samba
tries to use SMB1, which is deprecated and has security issues. This
container defaults to SMB2, but for no discernible reason, even though it's
supported, it is disabled by default. Run the command as `smbclient -m SMB3` along with
any other options you would specify.

### Issues

If you have any problems with or questions about this image, please contact me
through a [GitHub issue](https://github.com/adrianmusante/docker-samba/issues).