Skip to content
Markus Hartung edited this page Jul 1, 2018 · 6 revisions

Welcome to the samba wiki!


Example Usage For Common Sharing Scenarios

Concise and repurposable examples to illustrate common usage.
Open invite to add / update additional examples.

Create a read only share accessible by anyone at docker host ip.

Optionally:

  • Choose a name for the container
  • Set container to restart automatically
  • Enable the nmbd daemon to advertise the shares

Assuming:
Docker host has a folder /shared and should be accessible as \\host_ip\share_name

Command:
docker run -it --name samba --restart always --net=host -p 139:139 -p 455:455 -p 137:137/udp -p 138:138/udp -v /shared:/v_shared -d dperson/samba -s "share;/v_shared" -n

Explaination:
docker run -it docker run interactive terminal
--name samba [optional] pick a name for our container
--restart always [optional] auto restart on reboot
--net=host using the default host network
-p 139:139 -p 455:455 default smb port bindings
-p 137:137/udp -p 138:138/udp [optional] port bindings for 'nmbd' daemon to advertise the shares
-v /shared:/v_shared host folder /shared and where it will be mounted in the container /v_shared
-d dperson/samba container image
-s "share_name;/v_shared" the share nameshare_name and folder in container /v_shared to share
-n [optional] Start the 'nmbd' daemon to advertise the shares

More advanced example

I have a multi purpose printer with a scan to folder function. It only supports smb version 1 and has passed end of life so no further firmware updates will be released that supports newer samba versions. Docker host has already some samba shares and I don't want to downgrade them to version 1. So I found this to enable me to scan to folder using samba version 1.

First create a separate network for docker. Where lan is your local network adapter sudo docker network create -d macvlan -o "parent=lan" --subnet=192.168.1.0/24 --ip-range=192.168.1.0/26 --gateway=192.168.1.1 docker_lan

Create the container using this new network, note that I'm not using any accounts as it seems my printer were unable to use authentication: sudo docker run --network docker_lan -it --name samba -p 139:139 -p 445:445 -v /data/scan:/mnt/scan -d dperson/samba -p -s "scan;/mnt/scan;yes;no;yes;all" -g "min protocol = NT1"

Inspect the container to get its IP-address and MAC-address: sudo docker inspect samba

The docker network uses same scope as the LAN so you'll need to reserve the ip-address so you won't get any conflict with DHCP-server. So add this to your dnsmasq-config (or similar if you use other dhcp-server): dhcp-host=<MAC-address from inspect command>,192.168.1.X,scan
host-record=scan,192.168.1.X,86400

Clone this wiki locally