Skip to content

Docker With Samba Server#

What Is The Samba Server?#

  • A Samba file server enables file sharing across different operating systems over a network. It lets you access your desktop files from a laptop and share files with Windows and macOS users.

Create Samba Server With Docker#

  • Let's create a file name docker-compose.yml, then add scripts as below:
docker-compose.yml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
version: '3.4'

services:
  samba:
    image: dperson/samba
    environment:
      - TZ='Asia/Ho_Chi_Minh'
      - SHARE=Data;/mnt;yes;no;no;duc;none;none;Data
      - WORKGROUP=workgroup
      - USER=duc;itworked
      - NMBD=True
    networks:
      - default
    ports:
      - "137:137/udp"
      - "138:138/udp"
      - "139:139/tcp"
      - "445:445/tcp"
    read_only: false
    tmpfs:
      - /tmp
    restart: unless-stopped
    stdin_open: true
    tty: true
    volumes:
      - /home/duc/share:/mnt:z
networks:
  default:
  • In the environment, at line SHARE=Data;/mnt;yes;no;no;duc;none;none;Data please change the username duc to the username of the user that you define at line USER=duc;itworked. We have

    • Data: is the share name.
    • /mnt: The path inside the container that is being shared.
    • no: Whether guest access is allowed (no guest access).
    • no: whether the share is browsable.
    • none: Placeholder, possibly for a password or other options.
    • none: Placeholder, possibly for another option.
    • Data: The share comment or description.
  • USER=duc;itworked Creates a Samba user duc with the password itworked.

  • In the volumes we have /home/duc/share:/mnt:z : Mounts the host directory /home/duc/share to the container directory /mnt. The :z suffix is used for SELinux-enabled systems to apply the correct labels for shared volumes.

Testing#

  • Now you can use command docker-compose up to start your Samba server.
  • Then on your client machine let open Files then choose Other Locations. At the bottom let's put the prefix smb:// and the ip address of your server machine and click Connect

 #zoom

  • Then we will see the share name and when we double click on that, we will be required to put the username and password. So let's use the username and password that we created in the docker-compose.yml.

 #zoom

  • Then after we connected, we can share files between two machines.

 #zom

 #zoom

  • If you can not copy and paste file from your client machine, please check the read, write permission and owner on the share folder in your server machine. We can use command below to grant all permission on the share folder.
1
sudo chmod 777 -R /home/duc/share
  • Then for changing the owner of the folder.
1
sudo chown duc:duc -R /home/duc/share