docker.recipes

Syncthing with Relay Server

intermediate

Continuous file synchronization with self-hosted discovery and 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.

Key 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

Common Use Cases

  • 1Enterprise environments requiring complete data sovereignty and no external service dependencies
  • 2Remote development teams synchronizing code repositories and project files across distributed locations
  • 3Creative agencies sharing large media files between offices without expensive cloud storage limits
  • 4Homelab setups synchronizing configuration files and backups across multiple self-hosted services
  • 5Privacy-focused organizations avoiding commercial cloud providers for sensitive document sharing
  • 6Multi-site deployments needing reliable file sync between locations with varying network conditions
  • 7Educational 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

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 syncthing:
3 image: syncthing/syncthing:latest
4 container_name: syncthing
5 environment:
6 - PUID=1000
7 - PGID=1000
8 volumes:
9 - syncthing-config:/var/syncthing/config
10 - syncthing-data:/var/syncthing/data
11 ports:
12 - "8384:8384"
13 - "22000:22000/tcp"
14 - "22000:22000/udp"
15 - "21027:21027/udp"
16 networks:
17 - syncthing-network
18 restart: unless-stopped
19
20 discovery:
21 image: syncthing/discosrv:latest
22 container_name: syncthing-discovery
23 command: -listen=:8443
24 volumes:
25 - discovery-data:/var/discosrv
26 ports:
27 - "8443:8443"
28 networks:
29 - syncthing-network
30 restart: unless-stopped
31
32 relay:
33 image: syncthing/relaysrv:latest
34 container_name: syncthing-relay
35 command: -listen=:22067 -status-srv=:22070
36 volumes:
37 - relay-data:/var/relaysrv
38 ports:
39 - "22067:22067"
40 - "22070:22070"
41 networks:
42 - syncthing-network
43 restart: unless-stopped
44
45volumes:
46 syncthing-config:
47 syncthing-data:
48 discovery-data:
49 relay-data:
50
51networks:
52 syncthing-network:
53 driver: bridge

.env Template

.env
1# Syncthing with Relay
2# Configure clients to use your discovery and relay servers

Usage Notes

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

Individual Services(3 services)

Copy individual services to mix and match with your existing compose files.

syncthing
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
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
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

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 syncthing:
5 image: syncthing/syncthing:latest
6 container_name: syncthing
7 environment:
8 - PUID=1000
9 - PGID=1000
10 volumes:
11 - syncthing-config:/var/syncthing/config
12 - syncthing-data:/var/syncthing/data
13 ports:
14 - "8384:8384"
15 - "22000:22000/tcp"
16 - "22000:22000/udp"
17 - "21027:21027/udp"
18 networks:
19 - syncthing-network
20 restart: unless-stopped
21
22 discovery:
23 image: syncthing/discosrv:latest
24 container_name: syncthing-discovery
25 command: -listen=:8443
26 volumes:
27 - discovery-data:/var/discosrv
28 ports:
29 - "8443:8443"
30 networks:
31 - syncthing-network
32 restart: unless-stopped
33
34 relay:
35 image: syncthing/relaysrv:latest
36 container_name: syncthing-relay
37 command: -listen=:22067 -status-srv=:22070
38 volumes:
39 - relay-data:/var/relaysrv
40 ports:
41 - "22067:22067"
42 - "22070:22070"
43 networks:
44 - syncthing-network
45 restart: unless-stopped
46
47volumes:
48 syncthing-config:
49 syncthing-data:
50 discovery-data:
51 relay-data:
52
53networks:
54 syncthing-network:
55 driver: bridge
56EOF
57
58# 2. Create the .env file
59cat > .env << 'EOF'
60# Syncthing with Relay
61# Configure clients to use your discovery and relay servers
62EOF
63
64# 3. Start the services
65docker compose up -d
66
67# 4. View logs
68docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/syncthing-relay/run | bash

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

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Components

syncthingsyncthing-discoverysyncthing-relay

Tags

#sync#file-sharing#syncthing#p2p#backup

Category

Storage & Backup
Ad Space