This Docker image sets up Samba inside a docker container.
Samba is a free software re-implementation of the SMB networking protocol.
To use docker-samba, follow these steps:
-
Clone and start the container:
docker run -p 445:445 \ -e SAMBA_USER=bob \ -e SAMBA_PASS=123456 \ -v "${PWD}"/home:/home \ docker.io/aguslr/samba:latest
-
Configure your Samba client software to connect to your Samba server's IP address with user
SAMBA_USER
.
The image is configured using environment variables passed at runtime. All these
variables are prefixed by SAMBA_
.
Variable | Function | Default | Required |
---|---|---|---|
USER |
Username of Samba user | smbuser |
N |
PASS |
Password of Samba user | autogenerated | N |
UID |
UID of Samba user | 11000 | N |
PASSWDFILE |
Valid smbpasswd file |
empty | N |
USERSFILE |
File with user list | empty | N |
A default user is created with username smbuser
(or the value of SAMBA_USER
)
and an autogenerated password if none is provided with the variable
SAMBA_PASS
. To see the autogenerated password, check the log for the
container:
docker logs <container_name> | grep '^Password'
Alternatively, if a valid smbpasswd
file is provided, its users will be
added to the system and it will be imported using pdbedit
. The same tool
can be used to export the file from a working Samba setup:
pdbedit -e smbpasswd:/tmp/smbpasswd
A third option that provides finer control is provided. Using the variable
SAMBA_USERSFILE
, the path to a file with users' information can be passed to
the container.
This file should have one user per line in the format UID:NAME:GROUP:NTHASH
.
For example:
1000:smbuser:users:32ED87BDB5FDC5E9CBA88547376818D4
The command tool mkpasswd
can be used to get NT-Hashes from plain text
passwords:
mkpasswd --method=nt 123456
This command would ouput as used in the example above:
$3$$32ed87bdb5fdc5e9cba88547376818d4
To configure additional shares or parameters, we can add these to a smb.conf
file:
[Data]
path = /data
comment = Data directory
available = yes
browseable = yes
read only = yes
valid users = @users @nogroup
write list = @users
Then, we can go ahead and mount it as follows:
docker run -p 445:445 \
-e SAMBA_PASSWDFILE=/tmp/smbpasswd \
-v "${PWD}"/smbpasswd:/tmp/smbpasswd \
-v "${PWD}"/data:/data \
-v "${PWD}"/home:/home \
-v "${PWD}"/smb.conf:/etc/samba/includes.conf \
docker.io/aguslr/samba:latest
Instead of pulling the image from a remote repository, you can build it locally:
-
Clone the repository:
git clone https://github.com/aguslr/docker-samba.git
-
Change into the newly created directory and use
docker-compose
to build and launch the container:cd docker-samba && docker-compose up --build -d