Syncthing Setup Guide - ajgillis04/GillisDockerDepot GitHub Wiki

Syncthing Setup Guide

Introduction

Syncthing is a tool for keeping files identical between two locations. It creates a secure connection between your servers to ensure your data stays updated in real time. It is a robust way to manage backups or file sharing across your network.

💡 Why I switched: This setup replaces my reliance on the proprietary HBS3 system. I migrated to this method because switching from Traefik to Cloudflared caused complications with my previous offsite backup workflow. Syncthing proved to be a far more stable and reliable solution for keeping my data in sync.


Step 1: Environment Setup

  1. Add these variables to your root .env file. These ports allow the service to communicate across your network properly.
SYNCTHING_GUI_PORT=8384
SYNCTHING_LISTEN_PORT=22000
SYNCTHING_DISCOVERY_PORT=21027
  1. Copy the Compose file to your active server folder.
cp compose/templates/syncthing.yaml compose/server1/syncthing.yaml
  1. Create the directory for the configuration files.
sudo mkdir -p ${DOCKERDIR}/syncthing
  1. Launch the container.
docker compose -p mediaserver -f docker-compose-server1.yaml up -d syncthing

Step 2: Service Definition (syncthing.yaml)

# ------------------------------------------------------------------------------
# syncthing - Continuous File Synchronization
# ------------------------------------------------------------------------------
services:
  syncthing:
    container_name: syncthing.${HOST_NAME}
    hostname: syncthing.${HOST_NAME}.lan
    image: lscr.io/linuxserver/syncthing:latest
    environment:
      TZ: ${TZ}
      PUID: 0
      PGID: 0
      DOMAINNAME: ${DOMAINNAME}
      HOST_NAME: ${HOST_NAME}
    networks:
      - mediaserver
    ports:
      - ${SYNCTHING_GUI_PORT}:8384             # Web UI
      - ${SYNCTHING_LISTEN_PORT}:22000/tcp     # Sync protocol
      - ${SYNCTHING_LISTEN_PORT}:22000/udp     # Sync protocol
      - ${SYNCTHING_DISCOVERY_PORT}:21027/udp  # Local discovery
    volumes:
      - ${DOCKERDIR}/syncthing:/config      
      # Source folders to sync
      - /share/homes:/data/homes
      - ${MEDIASHARE}/Photos:/data/Photos
      - /share/Backups/GillisNAS/Docker/GillisDockerDepot:/data/Docker
      # Receiver
      - /share/Backups:/data/Backups
    restart: always
    security_opt:
      - no-new-privileges:true
    labels:
      - "com.centurylinklabs.watchtower.enable=true"
      - "homepage.group=Infrastructure"
      - "homepage.name=Syncthing"
      - "homepage.icon=syncthing.png"
      - "homepage.href=https://syncthing.${DOMAINNAME}/"
      - "homepage.description=Continuous file synchronization"

Step 3: Web Interface and Initial Configuration

  1. Open your browser and navigate to the address configured in your reverse proxy.
  2. The interface allows you to add remote devices using their unique IDs.
  3. You must share the device ID from one server and add it to the other to establish the connection.
  4. Once the devices are linked you can add specific folders to sync.

💡 Root Permissions Note: You have set this container to run with root permissions by using PUID 0 and PGID 0. This gives the service complete access to your system files. Ensure your host system is secure because this container can modify any file it has mounted.


Step 4: Troubleshooting

  • If devices cannot find each other ensure your firewall allows traffic on port 22000.
  • You can check the logs to see if the connection is failing by running the command below.
docker logs -f syncthing.${HOST_NAME}
  • The interface will show a status indicator at the top if the local discovery port is blocked.