Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

I chose to use this method → https://alexlubbock.com/convert-samba-docker as it uses the standard smb.conf which I already had and I prefer to use this method regardless. My main reason is documentation online will be in relating to editing SMB.CONF and I don't want to have to pass everytrhing through weird "envirvonment" variables and have to figure it all out again. It was as easy as coping my existing data over and firing up this container. This was the first container I deployed which doesn't have an "image" tag, but it's still fairly simple, it just comes with a "DOCKERFILE" which builds the image. 

You can view the file here → https://raw.githubusercontent.com/alubbock/samba-docker/master/Dockerfile and see how simple it is.

Update: Due to the extra volumes and my realize how simple it is, I have created my own DockerFile based on his and now use that.

Notes:

  • I don't expose /etc/shadow|passwd since I only use IP range permissions w/o PWD (home network)
  • All my shares are served under /mnt so I simply exposed that to the docker-container and voila, it all worked
  • Even after doing systemctl disable/stop samba I still had services (nmdb) using port 138. I had to use "netstat tulpn | grep 138" and kill them manually. Once this container was running I purged samba, enabled docker-container service at boot and reboot. Everything works as expected (smile)
  • There are a bunch of volumes created by this image that were not in the documentation which I mapped below as I prefer to use bind mounts in the same directory for persistence. (And my OCD, I have no "volumes" managed by docker, just bind mounts)

Docker-Compose:

WD=/opt/smbd
mkdir -p $WD/{mnt,setup,smb_conf}
cd $WD/setup
cat << 'EOF' >Dockerfile
FROM alpine

RUN apk add --update \
    samba-common-tools \
    samba-client \
    samba-server \
    && rm -rf /var/cache/apk/*

ENTRYPOINT ["smbd", "--foreground", "--log-stdout", "--no-process-group"]
CMD []
EOF
cat << 'EOF' >docker-compose.yaml
version: '3.7'

services:
 smbd:
    container_name: smbd
    hostname: smbd
    build: .
    container_name: samba
    ports:
      - "137:137/udp"
      - "138:138/udp"
      - "139:139/tcp"
      - "445:445/tcp"
    volumes:
      - type: bind
        read_only: true
        source: /opt/smbd/smb_conf/
        target: /etc/samba
      - type: bind
        source: /mnt
        target: /mnt
    environment:
      - 'TZ=America/Whitehorse'
EOF
chmod +x docker-compose.yaml

SystemD:

WD=/opt/smbd/setup
cat << EOF >$WD/smbd.service.setup.sh
cat << EOL >/lib/systemd/system/smbd.service
[Unit]
Description=smbd_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name smbd --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=/usr/bin/docker-compose --project-name smbd --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable smbd
systemctl restart smbd
systemctl status smbd
EOF
chmod +x $WD/smbd.service.setup.sh
$WD/smbd.service.setup.sh
  • No labels