Samba Server on Raspberry Pi with Docker

In this tutorial we will create a samba server on the raspberry pi using docker.

Samba is a file sharing service that allows windows clients to transfer files to and from, but not limited to windows, as linux clients can use cifs to interact with samba to access the shares.

Samba Server

I will create 2 directories on my server that I want to share:

$ mkdir -p /disk/3/backups
$ mkdir -p /disk/3/downloads

For this demonstration I will only password protect them with a very simple combination: username: guest, password: guest but its recommended to use a more complex password.

You will need to have Docker installed in order to run the samba container:

$ docker run -d -p 445:445 \
  --restart always \
  -v /disk/3/downloads:/share/downloads \
  -v /disk/3/backups:/share/backups \
  --name samba \
  trnape/rpi-samba -u "guest:guest" -s "Downloads:/share/downloads:rw:guest" -s "Backups:/share/backups:rw:guest"

As you can see we are mounting /disk/3/downloads from our local host directory to /share/downloads onto our container directory.

Then we are informing the container that we will use guest:guest as our username and password, and we are assigning that user/pass combination to our share and that the user has read/write access in :rw:guest

Mount From Linux

If you would like to access this share from a remote linux client, we first need to install the cifs-utils package:

$ sudo apt update
$ sudo apt install cifs-utils -y

Then mount using cifs:

$ mount -t cifs -o user=guest,pass=guest //192.168.0.115/backups /mnt

We should be able to see that our cifs mount is mounted:

$ df -h
Filesystem           Size  Used Avail Use% Mounted on  
/dev/root             28G   12G   16G  42% /
//192.168.0.115/backups  932G  517G  416G  56% /mnt

Mount on Boot

If you would like to mount this on boot, ensure that the target path has the desired permissions.

I am using the pi user:

$ chown -R pi:pi /mnt

Then as root edit your fstab file:

$ vim /etc/fstab

And append:

//192.168.0.115/backups /mnt cifs user=guest,pass=guest,_netdev,uid=pirate 0 0

After you saved, unmount the mount:

$ umount /mnt

Test the mount:

$ mount a

And you should see your mount:

$ df -h
Filesystem           Size  Used Avail Use% Mounted on  
/dev/root             28G   12G   16G  42% /
//192.168.0.115/backups  932G  517G  416G  56% /mnt