# Syncthing with Relay Server

> Continuous file synchronization with self-hosted discovery and relay.

- Category: Storage & Backup
- Difficulty: intermediate
- Components: syncthing, syncthing-discovery, syncthing-relay
- Tags: sync, file-sharing, syncthing, p2p, backup
- Source: https://docker.recipes/storage/syncthing-relay

## Overview

Syncthing is an open-source continuous file synchronization program that enables real-time, peer-to-peer file sharing across multiple devices without relying on cloud storage providers. Developed as a privacy-focused alternative to commercial sync services, Syncthing uses end-to-end encryption and operates entirely on a decentralized architecture, meaning your files never pass through third-party servers unless you explicitly configure relay servers for NAT traversal.

This stack combines the core Syncthing application with self-hosted discovery and relay infrastructure components. The syncthing-discovery service replaces the default public discovery servers, allowing devices to find each other within your private network or infrastructure. The syncthing-relay service provides NAT traversal capabilities for devices that cannot establish direct connections, such as mobile clients behind cellular networks or computers in restrictive corporate environments. Together, these components create a completely self-contained synchronization ecosystem that operates independently of Syncthing's public infrastructure.

This configuration is ideal for organizations requiring complete data sovereignty, homelab enthusiasts wanting full control over their sync infrastructure, or privacy-conscious users who prefer to minimize external dependencies. By hosting your own discovery and relay servers, you eliminate reliance on public Syncthing infrastructure while maintaining all the benefits of peer-to-peer synchronization, including conflict resolution, file versioning, and selective folder sharing across heterogeneous device ecosystems.

## Features

- Peer-to-peer file synchronization with no central storage server required
- Self-hosted discovery server eliminates dependency on public Syncthing discovery infrastructure
- Private relay server enables NAT traversal for devices behind firewalls or restrictive networks
- End-to-end encryption ensures files remain encrypted during transit and relay
- File versioning with configurable retention policies and conflict resolution
- Selective synchronization with ignore patterns and folder-level permissions
- Web-based management interface for device pairing and folder configuration
- Cross-platform device support including mobile, desktop, and server platforms

## Use cases

- Enterprise environments requiring complete data sovereignty and no external service dependencies
- Remote development teams synchronizing code repositories and project files across distributed locations
- Creative agencies sharing large media files between offices without expensive cloud storage limits
- Homelab setups synchronizing configuration files and backups across multiple self-hosted services
- Privacy-focused organizations avoiding commercial cloud providers for sensitive document sharing
- Multi-site deployments needing reliable file sync between locations with varying network conditions
- Educational institutions providing student file synchronization without external data processing agreements

## Prerequisites

- Minimum 512MB RAM allocated across all three containers (256MB for Syncthing, 128MB each for discovery and relay)
- Available ports 8384 (web UI), 8443 (discovery), 22000 (Syncthing protocol), 22067 (relay), 22070 (relay status), and 21027/UDP (local discovery)
- Understanding of Syncthing device IDs and folder sharing concepts for initial configuration
- Network firewall configuration allowing inbound connections on relay and discovery ports if serving external devices
- SSL/TLS certificate management knowledge if exposing discovery server over HTTPS to external networks
- Basic familiarity with Syncthing's ignore patterns and versioning configuration for folder management

## docker-compose.yml

```yaml
services:
  syncthing:
    image: syncthing/syncthing:latest
    container_name: syncthing
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - syncthing-config:/var/syncthing/config
      - syncthing-data:/var/syncthing/data
    ports:
      - "8384:8384"
      - "22000:22000/tcp"
      - "22000:22000/udp"
      - "21027:21027/udp"
    networks:
      - syncthing-network
    restart: unless-stopped

  discovery:
    image: syncthing/discosrv:latest
    container_name: syncthing-discovery
    command: -listen=:8443
    volumes:
      - discovery-data:/var/discosrv
    ports:
      - "8443:8443"
    networks:
      - syncthing-network
    restart: unless-stopped

  relay:
    image: syncthing/relaysrv:latest
    container_name: syncthing-relay
    command: -listen=:22067 -status-srv=:22070
    volumes:
      - relay-data:/var/relaysrv
    ports:
      - "22067:22067"
      - "22070:22070"
    networks:
      - syncthing-network
    restart: unless-stopped

volumes:
  syncthing-config:
  syncthing-data:
  discovery-data:
  relay-data:

networks:
  syncthing-network:
    driver: bridge
```

## .env

```bash
# Syncthing with Relay
# Configure clients to use your discovery and relay servers
```

## Usage notes

- Web UI at http://localhost:8384
- Discovery server at :8443
- Relay server at :22067
- Add folders and devices via UI
- End-to-end encrypted sync

## Troubleshooting

- Syncthing web UI shows 'connection refused': Check that port 8384 is properly mapped and not blocked by host firewall
- Devices cannot discover each other: Verify discovery server is accessible on port 8443 and configure custom discovery server URL in Syncthing settings
- Relay connection failures with 'no relay available': Ensure relay server port 22067 is accessible and properly configured in Syncthing relay settings
- High memory usage during large file sync: Increase container memory limits and consider adjusting Syncthing's database tuning parameters
- Files stuck in 'Syncing' state: Check for permission issues on mounted volumes and verify folder paths are correctly mapped between containers and host
- Discovery server fails to start with certificate errors: Generate proper SSL certificates or configure discovery server to run in HTTP-only mode for internal networks

