syncthing-file-replication-using-docker

SyncThing is a peer-to-peer file sync service, meaning that your devices form a direct connection instead of storing files on someone else's servers. If all those devices are on the same network, your files never leave that network (though SyncThing can work remotely as well).

How to run Syncthing in docker

For testing we are going to created 2 LXC container in proxmox server with docker installation.
And also named the lxc container syncthing-1 and syncthing-2.

Use the /var/syncthing volume to have the synchronized files available on the host. You can add more folders and map them as you prefer.

Note that Syncthing runs as UID 1000 and GID 1000 by default. These may be altered with the PUID and PGID environment variables. In addition the name of the Syncthing instance can be optionally defined by using --hostname=syncthing parameter.

Create the syncthing.example.com directory in srv folder for both syncthing-1 and syncthing-2.

mkdir -p /srv/syncthing.example.com

Create a docker-compose.yml file in syncthing.example.com directory for both syncthing-1 and syncthing-2.

name: syncthing-example-com

version: "2.4"

services:
  syncthing:
    image: syncthing/syncthing:latest
    container_name: syncthing.example.com
    hostname: syncthing # optional
    restart: always

    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/IST

    volumes:
      - ./appdata/config:/config
      - ./data:/var/syncthing
      - /srv:/srv # optional if you want to sync the /srv folder
      - /opt:/opt # optional if you want to sync the /opt folder

    ports:
      - 8384:8384
      - 22000:22000/tcp
      - 22000:22000/udp
      - 21027:21027/udp

Then run docker-compose up -d to start the Syncthing container.

Syncthing Configuration

The Syncthing configuration is stored in the /config volume. You can edit the configuration file /config/config.xml to change the Syncthing settings.

Syncthing Data

The Syncthing data is stored in the /var/syncthing volume. You can add more folders and map them as you prefer.

Syncthing Ports

The Syncthing ports are mapped as follows:

Syncthing Environment Variables

The Syncthing container can be customized with the following environment variables:

Syncthing Web UI

The Syncthing web UI is available at http://<your-ip>:8384 where you can add folders to sync and manage devices.

First update the username and password for the web UI.

2024-02-20 20_15_46-syncthing _ Syncthing 1.png

2024-02-20 20_16_10-syncthing _ Syncthing.png

2024-02-20 20_17_26-syncthing _ Syncthing 1.png

Disabling local and global discovery and relaying.

2024-02-20 20_17_52-syncthing _ Syncthing.png

  1. Direct connections only: Devices can only connect directly (peer-to-peer), bypassing the relay servers.
  2. No automatic discovery: Devices won't automatically find each other, requiring manual configuration of IP addresses.

2024-02-20 20_18_59-syncthing _ Syncthing.png

Copy the device ID and paste it into syncthing-1.

2024-02-20 20_19_31-syncthing _ Syncthing.png

Add remote devices

Click on Add Remote Device option and add the device in syncthing-1.

2024-02-20 20_22_58-syncthing _ Syncthing.png

Replace the syncthing-2 IP address in x.x.x.x

2024-02-20 20_24_22-syncthing _ Syncthing 1.png

Now in the syncthing-2 web UI the ask confirmation to add the device click on yes option.

Folder sharing

Click the Add Folder button in `syncthing-1.

2024-02-20 21_25_50-syncthing _ Syncthing.png

2024-02-20 21_26_16-syncthing _ Syncthing.png

2024-02-20 21_26_36-syncthing _ Syncthing.png

2024-02-20 21_26_45-syncthing _ Syncthing.png

2024-02-20 21_26_52-syncthing _ Syncthing.png

2024-02-20 21_27_13-syncthing _ Syncthing 1.png

2024-02-20 21_27_24-syncthing _ Syncthing 1.png

2024-02-20 21_28_23-syncthing _ Syncthing 1.png

2024-02-20 21_28_47-syncthing _ Syncthing 1.png

2024-02-20 21_29_11-syncthing _ Syncthing 1.png

2024-02-20 21_29_20-syncthing _ Syncthing 1.png

2024-02-20 21_29_35-syncthing _ Syncthing 1.png

2024-02-20 21_30_06-syncthing _ Syncthing 1.png

2024-02-20 21_30_26-syncthing _ Syncthing 1.png

Also copy below and create .stignore file in syncthing.example.com to ignore syncthing container.

syncthing.example.com/