# Syncthing P2P Sync

> Syncthing for peer-to-peer file synchronization.

- Category: Storage & Backup
- Difficulty: beginner
- Components: syncthing, nginx
- Tags: syncthing, sync, p2p, files
- Source: https://docker.recipes/storage/syncthing-sync-stack

## Overview

Syncthing is an open-source continuous file synchronization program that enables real-time, peer-to-peer file sharing between devices without relying on cloud services or centralized servers. Originally developed in 2013 as a privacy-focused alternative to commercial sync solutions, Syncthing uses end-to-end encryption and operates entirely on your own infrastructure, giving you complete control over your data while maintaining automatic synchronization across multiple devices.

This Docker stack combines Syncthing with NGINX to create a robust file synchronization platform where Syncthing handles the peer-to-peer sync operations and device communication while NGINX provides HTTP acceleration and can serve as a reverse proxy for the web interface. The combination addresses common deployment challenges like port management, SSL termination, and scaling across multiple Syncthing instances in larger environments.

This setup is ideal for privacy-conscious users, small teams, and organizations that need reliable file synchronization without monthly cloud storage fees or data sovereignty concerns. Home lab enthusiasts will appreciate the self-hosted nature, while small businesses benefit from unlimited storage capacity and no per-user licensing costs compared to commercial alternatives like Dropbox or Google Drive.

## Features

- Peer-to-peer synchronization with no central server or cloud dependency
- End-to-end AES encryption with TLS 1.3 for data in transit
- Real-time conflict detection and resolution with versioning support
- Selective folder sharing with granular device permissions
- Cross-platform device discovery via local broadcast and global discovery
- Web-based GUI for device management and folder configuration
- Bandwidth limiting and scheduling for sync operations
- NGINX reverse proxy support for SSL termination and caching

## Use cases

- Personal file synchronization between home computers, laptops, and mobile devices
- Small team document sharing without cloud storage subscriptions
- Photographer workflow for syncing RAW files between editing workstations
- Developer environment synchronization across multiple development machines
- Remote office backup strategy with automatic file replication
- Home media server synchronization for music and video libraries
- Secure document sharing for legal or healthcare practices requiring HIPAA compliance

## Prerequisites

- Minimum 256MB RAM for Syncthing operations and file monitoring
- Available ports 8384 (web UI), 22000 (sync), and 21027 (discovery)
- Persistent storage location for synchronized files (minimum 1GB recommended)
- Network connectivity between devices for peer-to-peer communication
- Basic understanding of device IDs and folder sharing concepts
- Firewall configuration allowing Syncthing discovery and sync ports

## docker-compose.yml

```yaml
services:
  syncthing:
    image: syncthing/syncthing:latest
    container_name: syncthing
    restart: unless-stopped
    hostname: syncthing
    ports:
      - "${SYNCTHING_PORT:-8384}:8384"
      - "22000:22000/tcp"
      - "22000:22000/udp"
      - "21027:21027/udp"
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - syncthing_config:/var/syncthing/config
      - ${SYNC_PATH:-./sync}:/var/syncthing/data

  nginx:
    image: nginx:alpine
    container_name: syncthing-nginx
    restart: unless-stopped
    ports:
      - "${NGINX_PORT:-80}:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro

volumes:
  syncthing_config:
```

## .env

```bash
# Syncthing
SYNCTHING_PORT=8384
SYNC_PATH=./sync
NGINX_PORT=80
```

## Usage notes

- Syncthing at http://localhost:8384
- Get device ID for pairing
- No cloud required
- End-to-end encrypted

## Troubleshooting

- Devices not discovering each other: Check firewall rules for ports 21027/udp and 22000, or manually add device IDs
- Sync conflicts appearing frequently: Enable file versioning in folder settings and check for clock synchronization between devices
- High CPU usage during initial sync: Adjust scan intervals in advanced folder settings and enable bandwidth limiting
- Web UI showing 'CSRF Error': Clear browser cache and cookies, or access via localhost instead of external IP
- Files not syncing after changes: Verify folder is not paused, check ignore patterns, and ensure sufficient disk space on target devices
- NGINX proxy returning 502 errors: Confirm Syncthing container is healthy and listening on port 8384 before NGINX starts

