Syncthing Setup Guide - ajgillis04/GillisDockerDepot GitHub Wiki
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.
- 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
- Copy the Compose file to your active server folder.
cp compose/templates/syncthing.yaml compose/server1/syncthing.yaml- Create the directory for the configuration files.
sudo mkdir -p ${DOCKERDIR}/syncthing- Launch the container.
docker compose -p mediaserver -f docker-compose-server1.yaml up -d syncthing# ------------------------------------------------------------------------------
# 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"- Open your browser and navigate to the address configured in your reverse proxy.
- The interface allows you to add remote devices using their unique IDs.
- You must share the device ID from one server and add it to the other to establish the connection.
- 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.
- 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.
This setup pairs two NAS boxes at different sites, and each one keeps the other's backup:
-
Sender side: the weekly container backup script writes to
/share/Backups/<this-server>/..., which Syncthing shares as a Send Only folder. -
Receiver side: the other NAS accepts it as a Receive Only folder under
/share/Backups/<other-server>/...(the/data/Backupsmount). - Keep a local copy too (for example a USB drive) as the first thing you restore from. The Syncthing copy is the offsite one.
Check both ends now and then. The folder state should be Up to Date on both, and the receiver's Local Additions / Locally Changed Items count should be 0.
Syncthing puts an empty .stfolder folder at the root of every shared folder. If it's missing (for example after the folder was moved, restored or cleaned), Syncthing stops the folder on purpose, so it can't mistake an unmounted disk for "everything deleted". If the path is correct and the disk is mounted, recreate the marker:
mkdir /share/Backups/<other-server>/<folder>/.stfolderThen click Rescan on the folder. The error clears and it catches up.
On a Receive Only folder, any file that differs from the sender counts as a local change, and that includes files that were deleted, or never arrived because of an older backup method. Syncthing doesn't fetch those again on its own. The folder can say Up to Date with "need 0" while thousands of files are missing.
- Open the folder on the receiver and check Locally Changed Items. Any number above 0 means the copy doesn't match the sender.
- If the sender is the correct copy, click Revert Local Changes. Syncthing deletes the receiver's own additions and downloads everything that's missing.
- Expect a long resync if a lot is missing; the folder shows progress until it's Up to Date again.
⚠️ Revert Local Changes deletes files that only exist on the receiver. Make sure the sender really is the copy you want before you click it.