Skip to content

Commit f9f6774

Browse files
committed
[Feat] Allow override of GUI's listen address from Syncthing
configuration file or environs - Replace hardcoded default listen address `0.0.0.0:8384` with 1. Environment variables lookup a. From `STGUIADDRESS` (eg: `0.0.0.0:4242`) b. From `STGUIHOST` (eg: `0.0.0.0`) and/or STGUIPORT (eg: `4242`) 2. Static configuration lookup from Syncthing config.xml 3. Default to `0.0.0.0` and `8384`
1 parent 2e8d0a3 commit f9f6774

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ COPY --from=buildstage /tmp/sync/syncthing /usr/bin/
5656
COPY root/ /
5757

5858
# ports and volumes
59-
EXPOSE 8384 22000/tcp 22000/udp 21027/UDP
59+
EXPOSE 8384 22000/tcp 22000/udp 21027/udp
6060
VOLUME /config

Dockerfile.aarch64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ COPY --from=buildstage /tmp/sync/syncthing /usr/bin/
5656
COPY root/ /
5757

5858
# ports and volumes
59-
EXPOSE 8384 22000/tcp 22000/udp 21027/UDP
59+
EXPOSE 8384 22000/tcp 22000/udp 21027/udp
6060
VOLUME /config

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ services:
7878
- PUID=1000
7979
- PGID=1000
8080
- TZ=Etc/UTC
81+
- STGUIADDRESS="0.0.0.0:8384" # optional
82+
- STGUIHOST=0.0.0.0 # optional
83+
- STGUIPORT=8384 # optional
8184
volumes:
8285
- /path/to/syncthing/config:/config
8386
- /path/to/data1:/data1
@@ -99,6 +102,9 @@ docker run -d \
99102
-e PUID=1000 \
100103
-e PGID=1000 \
101104
-e TZ=Etc/UTC \
105+
-e STGUIADDRESS="0.0.0.0:8384" `#optional` \
106+
-e STGUIHOST=0.0.0.0 `#optional` \
107+
-e STGUIPORT=8384 `#optional` \
102108
-p 8384:8384 \
103109
-p 22000:22000/tcp \
104110
-p 22000:22000/udp \
@@ -121,9 +127,12 @@ Containers are configured using parameters passed at runtime (such as those abov
121127
| `-p 22000:22000/tcp` | Listening port (TCP) |
122128
| `-p 22000:22000/udp` | Listening port (UDP) |
123129
| `-p 21027:21027/udp` | Protocol discovery |
124-
| `-e PUID=1000` | for UserID - see below for explanation |
125-
| `-e PGID=1000` | for GroupID - see below for explanation |
126-
| `-e TZ=Etc/UTC` | specify a timezone to use, see this [list](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List). |
130+
| `-e PUID=1000` | For UserID - see below for explanation |
131+
| `-e PGID=1000` | For GroupID - see below for explanation |
132+
| `-e TZ=Etc/UTC` | Specify a timezone to use, see this [list](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List). |
133+
| `-e STGUIADDRESS=0.0.0.0:8384` | Specify the application WebUI service listening address (default to `0.0.0.0:8384` if not overrided by env nor config.xml). Priority: env.STGUIADDRESS -> env.STGUIHOST/env.STGUIPORT -> config.xml -> default. |
134+
| `-e STGUIHOST=0.0.0.0` | Specify the application WebUI service listening host (default to `0.0.0.0` if not overrided by env nor config.xml). Priority: env.STGUIADDRESS -> env.STGUIHOST/env.STGUIPORT -> config.xml -> default. |
135+
| `-e STGUIPORT=8384` | Specify the application WebUI service listening port (default to `8384` if not overrided by env nor config.xml). Priority: env.STGUIADDRESS -> env.STGUIHOST/env.STGUIPORT -> config.xml -> default. |
127136
| `-v /config` | Configuration files. |
128137
| `-v /data1` | Data1 |
129138
| `-v /data2` | Data2 |
@@ -289,7 +298,7 @@ docker run --rm --privileged lscr.io/linuxserver/qemu-static --reset
289298
Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64`.
290299

291300
## Versions
292-
301+
* **06.12.25:** - [Feat] Allow override of GUI's listen address from Syncthing configuration file or environs
293302
* **16.08.25:** - Rebase to Alpine 3.22.
294303
* **13.08.25:** - Use double-dash long options for syncthing v2.0.0.
295304
* **03.12.24:** - Rebase to Alpine 3.21.

readme-vars.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ available_architectures:
1313
- {arch: "{{ arch_arm64 }}", tag: "arm64v8-latest"}
1414
# container parameters
1515
common_param_env_vars_enabled: true #PGID, PUID, etc, you can set it to 'optional'
16+
params_environs:
17+
- { environ: "STGUIADDRESS", optional: true, desc: "Override default (0.0.0.0:8384) or STGUIHOST/STGUIPORT or confix.xml application Web UI listen address. Priority: env.STGUIADDRESS -> env.STGUIHOST/env.STGUIPORT -> config.xml -> default."}
18+
- { environ: "STGUIHOST", optional: true, desc: "Override default (0.0.0.0) or config.xml application Web UI service listen host. Priority: env.STGUIADDRESS -> env.STGUIHOST/env.STGUIPORT -> config.xml -> default."}
19+
- { environ: "STGUIPORT", optional: true, desc: "Override default (8384) or config.xml application Web UI service listen port. Priority: env.STGUIADDRESS -> env.STGUIHOST/env.STGUIPORT -> config.xml -> default."}
1620
param_container_name: "{{ project_name }}"
1721
param_usage_include_hostname: 'optional' #you can set it to 'optional'
1822
param_hostname: "{{ project_name }}"
@@ -72,6 +76,7 @@ init_diagram: |
7276
"syncthing:latest" <- Base Images
7377
# changelog
7478
changelogs:
79+
- {date: "06.12.25:", desc: "[Feat] Allow override of GUI's listen address from Syncthing configuration file or environs"}
7580
- {date: "16.08.25:", desc: "Rebase to Alpine 3.22."}
7681
- {date: "13.08.25:", desc: "Use double-dash long options for syncthing v2.0.0."}
7782
- {date: "03.12.24:", desc: "Rebase to Alpine 3.21."}
Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4+
# Listen address lookup from:
5+
# 1. Environ
6+
# - 1. STGUIADDRESS
7+
# - 2. STGUIHOST and/or STGUIPORT
8+
# 2. Config (config.xml)
9+
# 3. Default (0.0.0.0:8384)
10+
11+
cfg_address=$(
12+
awk -v lookup=0 '
13+
$1 == "<gui" { lookup=1 }
14+
$1 == "</gui>" { lookup=0 }
15+
lookup == 1 { print }
16+
' /config/config.xml 2>/dev/null \
17+
| grep address \
18+
| sed 's|</\?address>||g; s|[[:space:]]||g'
19+
)
20+
21+
cfg_host="${cfg_address%%:*}"
22+
cfg_port="${cfg_address##*:}"
23+
24+
gui_address_host="${STGUIADDRESS%%:*}"
25+
gui_address_port="${STGUIADDRESS##*:}"
26+
27+
gui_host="${STGUIHOST:-$cfg_host}"
28+
gui_port="${STGUIPORT:-$cfg_port}"
29+
30+
gui_host="${gui_address_host:-$gui_host}"
31+
gui_port="${gui_address_port:-$gui_port}"
32+
33+
gui_host="${gui_host:-0.0.0.0}"
34+
gui_port="${gui_port:-8384}"
35+
36+
liveliness_target_host=$gui_host
37+
if [[ "x${gui_host}" == "x0.0.0.0" ]]; then
38+
liveliness_target_addr="127.0.0.1"
39+
fi
40+
441
exec \
5-
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 8384" \
42+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z ${liveliness_target_host} ${gui_port}" \
643
s6-setuidgid abc syncthing \
744
--home=/config --no-browser --no-restart \
8-
--gui-address="0.0.0.0:8384"
45+
--gui-address="${gui_host}:${gui_port}"

0 commit comments

Comments
 (0)