Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
991 lines (971 loc) · 41.5 KB
/
Copy pathdocker-compose.yml
File metadata and controls
991 lines (971 loc) · 41.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
# Personal Cloud — Seafile + Immich + Vaultwarden + Navidrome behind a hardened
# Caddy.
#
# ./scripts/init.sh # generate .env with strong secrets (run once)
# docker compose up -d # bring the stack up
# # register the Immich + Vaultwarden first accounts in the browser
# ./scripts/verify.sh # acceptance tests (file / password / photo)
#
# Hardening applied to every service: no-new-privileges, cap_drop ALL (+ only
# the capabilities an image genuinely needs), pinned images, internal networks
# for databases, and a single ingress (only Caddy publishes host ports).
# read_only root filesystem + tmpfs is applied wherever the upstream image
# tolerates it — every service here except seafile-server, whose stock image
# regenerates config and runs its own nginx across the rootfs. The per-service
# comments below say why each exception, capability and tmpfs flag is there.
#
# Memory budget (4 GB host): every long-running service has a mem_limit — a hard
# ceiling, not a reservation. Steady state is ~1.3-1.4 GB; the ceilings sum to
# ~5.1 GB on purpose, because the peaks don't coincide (the biggest, the Immich
# geodata import, lands while the ML model is idle). prod-setup.sh adds swap so a
# rare overlap is a slowdown, not an OOM kill. On a bigger host, raise the
# immich-db cache settings and the mem_limits proportionally.
name: private-cloud
x-restart: &restart unless-stopped
networks:
# Public-facing bridge. Has egress (apps need it for app store / model
# downloads). Fixed subnet keeps the proxy address range predictable.
proxy:
driver: bridge
ipam:
config:
- subnet: ${PROXY_SUBNET}
# Database tiers — internal:true blocks all egress; no published ports means
# they are unreachable from the host or the Internet.
immich-internal:
internal: true
seafile-internal:
internal: true
# immich-server <-> immich-ml only. NOT internal: ML downloads models on first
# use. Keeps the unauthenticated ML API off the shared proxy bridge.
ml: {}
# navidrome <-> navidrome-sonic only. The sidecar's API has no authentication.
sonic:
internal: true
# caddy <-> notification-server only. The sidecar needs no egress: config comes
# from env and its DB is on seafile-internal.
notification:
internal: true
volumes:
caddy_data:
vaultwarden_data:
immich_db:
immich_modelcache:
seafile_db:
# Local SSD — latency-sensitive data that must NOT live on the (network) Storage
# Box: the databases above, plus Seafile's conf/metadata and Immich's hot,
# constantly-read derivatives.
seafile_data: # Seafile /shared parent (the seafile_box mount nests under it)
seafile_logs: # Seafile logs — kept local (per-request access logs are chatty)
immich_thumbs: # Immich thumbnails (read on every grid/scroll)
immich_encoded: # Immich transcoded video
navidrome_data: # Navidrome SQLite DB (users, playlists, play counts) + art/transcode cache
# Embeddings and mood scores per track. Not backed up: navidrome-sonic rebuilds
# them from the library on its own, and they hold nothing a person entered.
navidrome_sonic_data:
navidrome_plugins: # sonic.ndp, copied in by navidrome-sonic on every start
# Uploads waiting for import; navidrome-upload caps it and empties it after
# each import. Not backed up.
navidrome_upload_staging:
# Storage Box — cheap bulk blobs over CIFS/SMB. ${SB_*} come from .env.
# LOCAL : docker-compose.storagebox-sim.yml runs a Samba server at ${SB_HOST}.
# PROD : ${SB_HOST} = u<id>.your-storagebox.de (a Hetzner Storage Box).
# Ownership is fixed by the mount's uid=/gid= (CIFS can't be chown'd), so this is
# NOT touched by volume-init. nobrl avoids CIFS byte-range-lock errors; the
# databases live on local SSD precisely so they never need locking over SMB.
# seal turns on SMB3 transport encryption (requires vers>=3.0, hence
# SB_SMB_VERS), set on every mount of this share — the two volumes here plus
# the host mounts in prod-setup.sh / backup.sh / restore.sh. Transport only:
# data lands on the box in plaintext, so snapshots hold plaintext and a restore
# needs no key. For at-rest encryption use a Seafile encrypted library.
# noexec,nosuid,nodev: the shares hold only blobs, config, avatars and music,
# never executables. Like any driver_opts change, applying these needs a
# `docker volume rm` + recreate.
# iocharset=utf8 (navidrome_music only): without it CIFS loads the kernel's
# default NLS and, when that module is not installed, falls back to a built-in
# Latin-1 table. A name macOS wrote in decomposed form ("u" + combining mark)
# then arrives with a literal "?" and cannot be opened. The option needs the
# nls_utf8 module, which prod-setup.sh checks for. The other shares hold only
# ASCII names their apps generate.
# nostrictsync (immich_data only): skip the server-side flush on fsync(). Photo
# ingest is many small write+fsync bursts where the round-trip to the box — not
# raw throughput — is the tax, so dropping the per-file flush is a documented
# ~2x win on this workload. The risk (bytes written-but-not-yet-flushed are lost
# on a host crash / network blip) is acceptable here: the phone is the source of
# truth and the scheduled Storage Box backup is the floor. Deliberately NOT on
# seafile_box, where a half-written commit may have no upstream copy.
# addr=${SB_HOST} is not redundant beside device:. Docker resolves the device
# hostname itself and puts the IP in the UNC, leaving the kernel an address where it
# expects a server name, so a box that moves to a new IP needs the mount recreated.
# With addr= the driver resolves that value and leaves the UNC alone: the kernel
# keeps the hostname and re-resolves it on reconnect.
immich_data: # Immich originals: library/ + upload/ (uid 1000)
driver: local
driver_opts:
type: cifs
device: "//${SB_HOST}/${SB_SHARE}/immich"
o: "username=${SB_USER},password=${SB_PASSWORD},addr=${SB_HOST},uid=1000,gid=1000,file_mode=0700,dir_mode=0700,vers=${SB_SMB_VERS},cache=loose,nobrl,seal,nostrictsync,noexec,nosuid,nodev"
seafile_box: # Seafile data tree: object store + conf + seahub-data (uid 8000)
driver: local
driver_opts:
type: cifs
device: "//${SB_HOST}/${SB_SHARE}/seafile"
o: "username=${SB_USER},password=${SB_PASSWORD},addr=${SB_HOST},uid=8000,gid=8000,file_mode=0700,dir_mode=0700,vers=${SB_SMB_VERS},cache=loose,nobrl,seal,noexec,nosuid,nodev"
navidrome_music: # the music library, as plain files you copy onto the box (uid 1002)
driver: local
driver_opts:
type: cifs
device: "//${SB_HOST}/${SB_SHARE}/music"
o: "username=${SB_USER},password=${SB_PASSWORD},addr=${SB_HOST},uid=1002,gid=1002,file_mode=0700,dir_mode=0700,vers=${SB_SMB_VERS},cache=loose,nobrl,seal,noexec,nosuid,nodev,iocharset=utf8"
services:
# --------------------------------------------------------------- ingress --
caddy:
image: ${CADDY_IMAGE}
container_name: pc-caddy
restart: *restart
mem_limit: 96m
# Fork-bomb / runaway-spawn cap; Caddy is a single Go process.
pids_limit: 64
# Non-root: Caddy is the edge (the only container with published ports), so it
# runs unprivileged instead of root — shrinking container-escape surface and
# making volume writes non-root-owned. uid 1001 is deliberately distinct from the
# uid-1000 apps (vaultwarden/immich) so a Caddy compromise shares ownership with
# none of their volumes. It keeps only NET_BIND_SERVICE (see cap_add) to bind
# 80/443. volume-init chowns caddy_data to 1001 (the cert store + internal-CA
# key live in /data).
user: "1001:1001"
ports:
- "${HTTP_PORT}:80"
- "${HTTPS_PORT}:443"
environment:
IMMICH_DOMAIN: ${IMMICH_DOMAIN}
VAULTWARDEN_DOMAIN: ${VAULTWARDEN_DOMAIN}
SEAFILE_DOMAIN: ${SEAFILE_DOMAIN}
NAVIDROME_DOMAIN: ${NAVIDROME_DOMAIN}
CADDY_TLS: ${CADDY_TLS}
# Go listens with MPTCP by default, and the reported CVE-2026-98432 exploit goes
# through an MPTCP listener. Plain TCP only. Not the net.mptcp.enabled sysctl:
# it fails container start on kernels without MPTCP.
GODEBUG: multipathtcp=0
volumes:
- ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
# No /config volume: persist_config off (Caddyfile) means it is never written.
networks:
- proxy
- notification
read_only: true
# noexec/nosuid/nodev: /tmp is the one writable path on the read-only rootfs,
# so deny running a dropped binary there. size caps it.
tmpfs:
- /tmp:noexec,nosuid,nodev,size=16m
cap_drop: [ALL]
# NET_BIND_SERVICE: the only cap, needed to bind 80/443 as non-root. The official
# image's caddy binary carries this as a *file* capability, so it must stay in the
# bounding set — dropping it makes the exec itself fail (EPERM), not just the bind.
cap_add: [NET_BIND_SERVICE]
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:2019/config/"]
interval: 15s
timeout: 5s
retries: 5
start_period: 10s
depends_on:
volume-init:
condition: service_completed_successfully
immich-server:
condition: service_started
vaultwarden:
condition: service_started
seafile-server:
condition: service_started
navidrome:
condition: service_started
# ------------------------------------------------------------ vaultwarden --
# One-shot chowner so the non-root services own their LOCAL data volumes before
# they start: vaultwarden + immich run as uid 1000, caddy as uid 1001 (a distinct
# uid so a Caddy compromise can't touch the other services' volumes), seafile's
# daemons as uid 8000 (Seafile's NON_ROOT mode refuses to start unless /shared is
# writable). The CIFS Storage Box volume (immich_data) is excluded — its ownership
# comes from the mount's uid=, and CIFS can't be chown'd anyway.
volume-init:
image: alpine:3.20
container_name: pc-volume-init
command:
[
"sh",
"-c",
"chown -R 1000:1000 /vw && chmod 700 /vw && chown -R 1000:1000 /immich-thumbs /immich-encoded /immich-modelcache && chown -R 1001:1001 /caddy-data && chown -R 8000:8000 /seafile /seafile-logs && chown -R 1002:1002 /navidrome-data /navidrome-sonic-data /navidrome-plugins /navidrome-upload-staging",
]
volumes:
- vaultwarden_data:/vw
- navidrome_data:/navidrome-data
- navidrome_sonic_data:/navidrome-sonic-data
- navidrome_plugins:/navidrome-plugins
- navidrome_upload_staging:/navidrome-upload-staging
- immich_thumbs:/immich-thumbs
- immich_encoded:/immich-encoded
- immich_modelcache:/immich-modelcache
- caddy_data:/caddy-data
- seafile_data:/seafile
- seafile_logs:/seafile-logs
restart: "no"
security_opt:
- no-new-privileges:true
vaultwarden:
image: ${VAULTWARDEN_IMAGE}
container_name: pc-vaultwarden
restart: *restart
mem_limit: 96m
user: "1000:1000"
environment:
DOMAIN: ${VAULTWARDEN_URL}
ROCKET_ADDRESS: 0.0.0.0
ROCKET_PORT: "8080"
DATA_FOLDER: /data
SIGNUPS_ALLOWED: ${VAULTWARDEN_SIGNUPS_ALLOWED}
ADMIN_TOKEN: ${VAULTWARDEN_ADMIN_TOKEN}
PASSWORD_HINTS_ALLOWED: "false"
# Caddy is the only upstream and sets X-Forwarded-For; the default
# (X-Real-IP) is never set, so every request would otherwise look like it
# comes from Caddy's IP — collapsing the login rate-limiter to a single
# global bucket and hiding real client IPs from the logs.
IP_HEADER: X-Forwarded-For
# Serve API only — disable the standalone web vault UI to shed that
# client-side surface. Browser extensions and native apps still work.
WEB_VAULT_ENABLED: "false"
TZ: ${TZ}
# Outgoing mail (invite / password-hint / 2FA notices). Unset SMTP_HOST
# disables mail in Vaultwarden, which is the default in .env.example.
# The same SMTP_* values feed Seafile via scripts/harden-seafile.sh.
SMTP_HOST: ${SMTP_HOST}
SMTP_PORT: ${SMTP_PORT}
SMTP_SECURITY: ${SMTP_SECURITY}
SMTP_FROM: ${SMTP_FROM}
SMTP_FROM_NAME: ${SMTP_FROM_NAME}
SMTP_USERNAME: ${SMTP_USERNAME}
SMTP_PASSWORD: ${SMTP_PASSWORD}
volumes:
- vaultwarden_data:/data
networks:
- proxy
depends_on:
volume-init:
condition: service_completed_successfully
read_only: true
# noexec/nosuid/nodev: the only writable paths on a read-only rootfs are scratch
# — never a place to run a dropped binary, hold a setuid bit, or mknod a device.
tmpfs:
- /tmp:noexec,nosuid,nodev
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
healthcheck:
test:
[
"CMD-SHELL",
"wget -qO- http://127.0.0.1:8080/alive >/dev/null 2>&1 || exit 1",
]
interval: 30s
timeout: 5s
retries: 5
start_period: 20s
# ----------------------------------------------------------------- immich --
immich-db:
image: ${IMMICH_DB_IMAGE}
container_name: pc-immich-db
restart: *restart
# 768M (not 512M): steady state is ~100M, but Immich's one-time first-boot
# reverse-geocoding import (geodata_places) peaks at ~680M. A 512M cap OOM-kills
# that import on a fresh DB (signal 9 mid-INSERT). 768M clears it with headroom.
mem_limit: 768m
shm_size: 128mb
# Pin memory so the image does not auto-tune shared_buffers/effective_cache_size
# to the host's total RAM (it would grab ~25% of the 4 GB box otherwise). We
# MUST keep the image's default `-c config_file=...` first — that conf holds the
# VectorChord shared_preload_libraries; the later -c flags override only the
# memory params (command-line -c wins over the config file).
command:
- postgres
- -c
- config_file=/etc/postgresql/postgresql.conf
- -c
- shared_buffers=128MB
- -c
- effective_cache_size=384MB
- -c
- maintenance_work_mem=64MB
- -c
- work_mem=8MB
- -c
- max_connections=30
- -c
- max_parallel_workers=2
- -c
- max_parallel_workers_per_gather=1
- -c
- max_parallel_maintenance_workers=1
environment:
POSTGRES_DB: ${IMMICH_DB_NAME}
POSTGRES_USER: ${IMMICH_DB_USER}
POSTGRES_PASSWORD: ${IMMICH_DB_PASSWORD}
POSTGRES_INITDB_ARGS: "--data-checksums"
volumes:
- immich_db:/var/lib/postgresql/data
networks:
- immich-internal
read_only: true
# noexec/nosuid/nodev: scratch, socket, and regenerated-config dirs — none run
# code, hold setuid bits, or need device nodes.
tmpfs:
- /tmp:noexec,nosuid,nodev
- /run/postgresql:noexec,nosuid,nodev
# The immich postgres image writes a tuned config here on every start.
- /etc/postgresql:noexec,nosuid,nodev
cap_drop: [ALL]
# The entrypoint starts as root to chown the data dir, then drops to the
# postgres user — CHOWN/DAC_OVERRIDE/FOWNER for the first, SETGID/SETUID for
# the second. Nothing else is granted.
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETGID, SETUID]
security_opt:
- no-new-privileges:true
healthcheck:
test:
["CMD-SHELL", "pg_isready -U ${IMMICH_DB_USER} -d ${IMMICH_DB_NAME}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 90s
immich-redis:
image: ${VALKEY_IMAGE}
container_name: pc-immich-redis
restart: *restart
mem_limit: 96m
user: "999:1000"
# No maxmemory/eviction policy: this Valkey is Immich's BullMQ job broker, so
# evicting keys would silently drop queued jobs. The mem_limit is the only cap.
command:
- valkey-server
- --requirepass
- ${IMMICH_REDIS_PASSWORD}
- --save
- ""
- --appendonly
- "no"
environment:
REDISCLI_AUTH: ${IMMICH_REDIS_PASSWORD}
networks:
- immich-internal
read_only: true
# noexec/nosuid/nodev: scratch + ephemeral data dir, neither runs code.
tmpfs:
- /tmp:noexec,nosuid,nodev
- /data:noexec,nosuid,nodev
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
healthcheck:
test:
[
"CMD-SHELL",
'valkey-cli -a "$$REDISCLI_AUTH" --no-auth-warning ping | grep -q PONG',
]
interval: 10s
timeout: 5s
retries: 5
immich-server:
image: ghcr.io/open-noodle/gallery-server:${IMMICH_VERSION}
container_name: pc-immich-server
restart: *restart
# 2048m (not 1024m): steady state is ~800M, but the boot-time geodata import
# (227k records, re-runs whenever the bundled cities500 dataset changes) peaks
# at ~1.5G. Under a 1024m cap that import is OOM-killed before it finishes, so
# the container restarts and re-imports forever — a crash loop that still logs
# a full, healthy-looking boot each cycle, so the only direct evidence is
# `docker events` (oom / die exit=137) or memory.peak in the container cgroup.
# The spike is off-heap, so the V8 cap below stays at 768M. mem_limit is a
# ceiling, not a reservation: this costs nothing at rest.
mem_limit: 2048m
# No `cpus:` cap: it throttled this container against otherwise-idle CPU.
# Priority now comes from immich-ml's lower cpu_shares; this service keeps the
# default weight, as do the databases and the rest of the stack.
user: "1000:1000"
environment:
# Cap the V8 heap below the mem_limit so Node garbage-collects under pressure
# instead of being OOM-killed (leaves headroom for off-heap libvips buffers).
NODE_OPTIONS: "--max-old-space-size=768"
# The image preloads mimalloc, which returns freed memory to the OS only on a
# later allocator call. After a thumbnail burst the libvips threads go idle and
# never make one, so the job worker keeps the burst's memory. These purge at
# free time and reclaim freed pages sooner. Measured: ~0.75 GiB less one minute
# after a burst, same CPU time.
MIMALLOC_PURGE_DELAY: "0"
MIMALLOC_ARENA_PURGE_MULT: "1"
MIMALLOC_GENERIC_COLLECT: "100"
MIMALLOC_PAGE_RECLAIM_ON_FREE: "1"
DB_HOSTNAME: immich-db
DB_USERNAME: ${IMMICH_DB_USER}
DB_PASSWORD: ${IMMICH_DB_PASSWORD}
DB_DATABASE_NAME: ${IMMICH_DB_NAME}
REDIS_HOSTNAME: immich-redis
REDIS_PASSWORD: ${IMMICH_REDIS_PASSWORD}
IMMICH_MACHINE_LEARNING_URL: http://immich-ml:3003
TZ: ${TZ}
# Hardening: TRUSTED_PROXIES lets Immich read the real client IP from Caddy's
# X-Forwarded-For (login rate-limiter + audit logs see the client, not the
# proxy). PROXY_SUBNET is the only network Caddy reaches it on. The
# admin-sign-up endpoint is open until you register the first admin in the
# browser, then self-closes, so IMMICH_ALLOW_SETUP is left at Immich's
# default. System settings
# (version-check, ML, sharing, …) stay editable in the admin UI at Immich's
# defaults — NOT pinned via a config file.
IMMICH_TRUSTED_PROXIES: ${PROXY_SUBNET}
volumes:
# Originals on the Storage Box; hot derivatives carved back to local SSD.
# /data itself is the CIFS mount, so Immich's upload->library move stays
# intra-device (no cross-device rename); thumbs + transcodes are local.
- immich_data:/data
- immich_thumbs:/data/thumbs
- immich_encoded:/data/encoded-video
- /etc/localtime:/etc/localtime:ro
networks:
- proxy
- immich-internal
- ml
depends_on:
volume-init:
condition: service_completed_successfully
immich-db:
condition: service_healthy
immich-redis:
condition: service_healthy
read_only: true
# noexec/nosuid/nodev: /tmp is scratch only (uploads stream to /data); native
# modules load from node_modules on the rootfs, never from here.
tmpfs:
- /tmp:noexec,nosuid,nodev
# No cap_add: runs as uid 1000, where added caps never become effective
# (they only land in the bounding set).
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
# Also stat the Storage Box CIFS mount (library/ is on the box; thumbs/ and
# encoded-video/ are local) so a wedged SMB session reads as unhealthy, not
# healthy-with-dead-storage. Recovery: scripts/mount-watchdog.sh.
healthcheck:
test:
[
"CMD-SHELL",
"immich-healthcheck && timeout 8 stat /data/library >/dev/null 2>&1",
]
interval: 30s
timeout: 15s
retries: 5
start_period: 120s
# Optional. Carves previews back out to the Storage Box. Immich puts both
# derivatives of an asset in the same thumbs/ directory and separates them by
# filename only, so there is no mount (and no Immich setting) that can split
# them — a sweep moves the previews and symlinks them, keeping the small,
# scroll-hot thumbnails on local SSD, and monthly deletes the ones on the box
# that nothing points at any more. Rationale and failure modes:
# scripts/immich-preview-mover.sh.
# Nothing else depends on this service: delete it and Immich runs unchanged with
# previews on local SSD. Previews it already moved keep working either way, since
# immich-server resolves their symlinks over the mount it holds itself.
# It mounts the same two volumes as immich-server at the same paths, so the
# symlink targets it writes resolve identically in both containers.
immich-preview-mover:
image: alpine:3.20
container_name: pc-immich-preview-mover
restart: *restart
# A busybox find over the thumbs tree; the copies stream through cp.
mem_limit: 32m
user: "1000:1000"
command: ["sh", "/scripts/immich-preview-mover.sh"]
volumes:
- immich_data:/data
- immich_thumbs:/data/thumbs
# The directory, not the file: a single-file bind mount pins the container to
# the inode it started with, so editing the script leaves the container
# running — and `exec`ing — the old copy. Through a directory the lookup
# resolves each time, so --reclaim always runs what is on disk.
- ./scripts:/scripts:ro
depends_on:
volume-init:
condition: service_completed_successfully
read_only: true
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
immich-ml:
image: ghcr.io/open-noodle/gallery-ml:${IMMICH_VERSION}
container_name: pc-immich-ml
restart: *restart
mem_limit: 1280m
# Relative CPU priority rather than a hard cap. A `cpus:` quota throttles this
# container even when the rest of the stack is idle, and a throttled cgroup is
# frozen for the remainder of each scheduling period, which surfaces as request
# latency. A share only binds when something else actually wants the CPU: ML
# holds roughly its old ceiling while immich-server is busy, and can use
# whatever is spare when it is not. The odd value is deliberate — Docker
# rescales cpu_shares into a cgroup2 weight, and the seemingly neutral 1024
# lands well *below* the default weight every other container here has.
cpu_shares: 1550
user: "1000:1000"
environment:
TZ: ${TZ}
HOME: /cache
# gunicorn (25.x) opens a control socket in its working dir (/usr/src) for the
# `gunicornc` admin tool. That dir is root-owned and read-only here, so the
# default path can't be created and boot would log a benign but noisy ERROR
# ("Control server: ... Read-only file system"). Relocate it onto the /tmp
# tmpfs so it works regardless — including if MACHINE_LEARNING_WORKERS is ever
# raised, where the master uses this socket to manage the workers.
GUNICORN_CMD_ARGS: "--control-socket /tmp/gunicorn.ctl"
# Keep the ML peak bounded for the 4 GB box: unload idle models after 5 min,
# a single worker, and serialized inference so concurrent jobs don't stack
# multiple model copies in RAM. Jobs throttle/retry rather than OOM the host.
MACHINE_LEARNING_MODEL_TTL: "300"
MACHINE_LEARNING_WORKERS: "1"
MACHINE_LEARNING_REQUEST_THREADS: "1"
MACHINE_LEARNING_MODEL_REVISION: "v2"
volumes:
- immich_modelcache:/cache
# ml only: nothing but immich-server needs to reach the unauthenticated ML API.
networks:
- ml
depends_on:
volume-init:
condition: service_completed_successfully
read_only: true
# nosuid/nodev only — NOT noexec: the ML worker's native deps (onnxruntime et al.)
# mmap executable pages from a file under /tmp at import, so noexec kills worker
# boot (gunicorn master stays up but /ping never answers -> unhealthy). Verified
# on the live stack. /tmp also holds the gunicorn control socket; model/JIT caches
# live under HOME=/cache.
tmpfs:
- /tmp:nosuid,nodev
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
# ---------------------------------------------------------------- seafile --
# Reliable file sync with client-side encrypted libraries (the E2EE that
# actually works on iOS). MariaDB + Redis are fully hardened like the other
# data tiers; the Seafile app image keeps init/nginx as root but runs the
# seaf-server/seahub daemons non-root via NON_ROOT.
seafile-db:
image: ${SEAFILE_DB_IMAGE}
container_name: pc-seafile-db
restart: *restart
# innodb-buffer-pool-size is hard-capped at 96M below; 160M gives ~64M headroom
# for per-connection overhead, sort buffers, and the MariaDB process itself.
mem_limit: 160m
# Trim MariaDB's footprint (the entrypoint prepends `mariadbd` to these flags).
command:
- --innodb-buffer-pool-size=96M
- --innodb-log-buffer-size=8M
- --performance-schema=OFF
- --key-buffer-size=8M
- --skip-name-resolve
environment:
MYSQL_ROOT_PASSWORD: ${SEAFILE_DB_ROOT_PASSWORD}
MYSQL_LOG_CONSOLE: "true"
MARIADB_AUTO_UPGRADE: "1"
volumes:
- seafile_db:/var/lib/mysql
networks:
- seafile-internal
read_only: true
# noexec/nosuid/nodev: scratch (temp tables) + the mysqld socket dir; no code runs
# from either.
tmpfs:
- /tmp:noexec,nosuid,nodev
- /run/mysqld:noexec,nosuid,nodev
cap_drop: [ALL]
# Same minimal set as the Postgres tier: entrypoint chown, then drop to mysql.
cap_add: [CHOWN, DAC_OVERRIDE, FOWNER, SETGID, SETUID]
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 20s
timeout: 5s
retries: 10
start_period: 40s
# Same Valkey image as immich-redis (one image to pull/pin/patch); Seafile's
# CACHE_PROVIDER=redis speaks the plain Redis protocol, which Valkey implements.
seafile-redis:
image: ${VALKEY_IMAGE}
container_name: pc-seafile-redis
restart: *restart
mem_limit: 96m
user: "999:1000"
command:
- valkey-server
- --requirepass
- ${SEAFILE_REDIS_PASSWORD}
- --save
- ""
- --appendonly
- "no"
# Pure cache (Seafile CACHE_PROVIDER=redis): bound it and evict LRU keys.
- --maxmemory
- 48mb
- --maxmemory-policy
- allkeys-lru
environment:
REDISCLI_AUTH: ${SEAFILE_REDIS_PASSWORD}
networks:
- seafile-internal
read_only: true
# noexec/nosuid/nodev: scratch + ephemeral data dir, neither runs code.
tmpfs:
- /tmp:noexec,nosuid,nodev
- /data:noexec,nosuid,nodev
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
healthcheck:
test:
[
"CMD-SHELL",
'valkey-cli -a "$$REDISCLI_AUTH" --no-auth-warning ping | grep -q PONG',
]
interval: 10s
timeout: 5s
retries: 5
seafile-server:
image: ${SEAFILE_IMAGE}
container_name: pc-seafile
restart: *restart
# Fits the stack's budget only with seahub cut from 5 gunicorn workers to 2
# (~430 MB) — scripts/harden-seafile.sh does that after a fresh setup.
mem_limit: 640m
# Fork-bomb cap. Steady state is ~two dozen processes (my_init, nginx, seaf-server,
# 2 seahub gunicorn workers, go-fileserver).
pids_limit: 200
environment:
SEAFILE_MYSQL_DB_HOST: seafile-db
SEAFILE_MYSQL_DB_PORT: "3306"
SEAFILE_MYSQL_DB_USER: seafile
SEAFILE_MYSQL_DB_PASSWORD: ${SEAFILE_DB_PASSWORD}
SEAFILE_MYSQL_DB_CCNET_DB_NAME: ccnet_db
SEAFILE_MYSQL_DB_SEAFILE_DB_NAME: seafile_db
SEAFILE_MYSQL_DB_SEAHUB_DB_NAME: seahub_db
TIME_ZONE: ${TZ}
# The first-boot-only INIT_SEAFILE_ADMIN_* and INIT_SEAFILE_MYSQL_ROOT_PASSWORD
# are intentionally NOT here: they would otherwise persist in the long-running
# container env (`docker inspect pc-seafile`). They are supplied transiently by
# docker-compose.setup.yml during initial provisioning only. See that file.
# Hostname includes the port so Seahub emits correct absolute URLs and
# CSRF origins on the non-standard local HTTPS port (harmless :443 in prod).
SEAFILE_SERVER_HOSTNAME: "${SEAFILE_DOMAIN}:${HTTPS_PORT}"
SEAFILE_SERVER_PROTOCOL: https
SITE_ROOT: /
# Drop the seaf-server/seahub daemons to uid 8000 (init/nginx stay root).
NON_ROOT: "true"
JWT_PRIVATE_KEY: ${SEAFILE_JWT_KEY}
SEAFILE_LOG_TO_STDOUT: "false"
ENABLE_GO_FILESERVER: "true"
ENABLE_NOTIFICATION_SERVER: "true"
# The address the browser dials — the Caddyfile's /notification route — and
# the one seaf-server posts its events to.
NOTIFICATION_SERVER_URL: "https://${SEAFILE_DOMAIN}:${HTTPS_PORT}/notification"
INNER_NOTIFICATION_SERVER_URL: "http://notification-server:8083"
# Optional extras kept off to stay lean (file sync + E2EE only).
ENABLE_SEADOC: "false"
ENABLE_SEAFILE_AI: "false"
ENABLE_FACE_RECOGNITION: "false"
CACHE_PROVIDER: redis
REDIS_HOST: seafile-redis
REDIS_PORT: "6379"
REDIS_PASSWORD: ${SEAFILE_REDIS_PASSWORD}
volumes:
- seafile_data:/shared
# Mount the Storage Box one level ABOVE seafile-data: the bootstrap skips
# first-run setup iff /shared/seafile/seafile-data exists, so mounting the
# (empty) box at /shared/seafile lets setup run and create seafile-data on the
# box — single-shot, no two-phase. DB metadata stays in MariaDB (local); logs
# go to a local volume (below) so nothing chatty is written over CIFS.
- seafile_box:/shared/seafile
- seafile_logs:/shared/seafile/logs
networks:
- proxy
- seafile-internal
depends_on:
volume-init:
condition: service_completed_successfully
seafile-db:
condition: service_healthy
seafile-redis:
condition: service_started
# read_only not applied — the seafile-mc image regenerates config and runs
# its own nginx/my_init across the rootfs. Still hardened: cap_drop ALL +
# no-new-privileges + non-root daemons (NON_ROOT) + internal-only DB/cache.
cap_drop: [ALL]
cap_add:
[CHOWN, DAC_OVERRIDE, FOWNER, SETGID, SETUID, NET_BIND_SERVICE, KILL]
security_opt:
- no-new-privileges:true
healthcheck:
# Also stat the Storage Box CIFS mount (a child path forces a network
# revalidate) so a wedged SMB session reads as unhealthy, not
# healthy-with-dead-storage. Recovery: scripts/mount-watchdog.sh.
test:
[
"CMD-SHELL",
"curl -fsS http://127.0.0.1:80/ >/dev/null 2>&1 && timeout 8 stat /shared/seafile/seafile-data >/dev/null 2>&1",
]
interval: 30s
timeout: 12s
retries: 10
start_period: 180s
# ----------------------------------------------------- notification server --
# The service key must stay `notification-server`: it is the host in
# seafile-server's INNER_NOTIFICATION_SERVER_URL.
notification-server:
image: ${NOTIFICATION_SERVER_IMAGE}
container_name: pc-notification
restart: *restart
# Idles at ~3M; the ceiling is headroom, not a target.
mem_limit: 64m
pids_limit: 128
environment:
SEAFILE_MYSQL_DB_HOST: seafile-db
SEAFILE_MYSQL_DB_PORT: "3306"
SEAFILE_MYSQL_DB_USER: seafile
SEAFILE_MYSQL_DB_PASSWORD: ${SEAFILE_DB_PASSWORD}
SEAFILE_MYSQL_DB_CCNET_DB_NAME: ccnet_db
SEAFILE_MYSQL_DB_SEAFILE_DB_NAME: seafile_db
JWT_PRIVATE_KEY: ${SEAFILE_JWT_KEY}
TIME_ZONE: ${TZ}
SEAFILE_LOG_TO_STDOUT: "false"
NOTIFICATION_SERVER_LOG_LEVEL: info
volumes:
- seafile_logs:/shared/seafile/logs
networks:
- notification
- seafile-internal
depends_on:
seafile-db:
condition: service_healthy
seafile-server:
condition: service_healthy
# Unlike seafile-server, this image's CMD is the Go binary itself (no my_init),
# so it runs as uid 8000 (owns the log dir) with a read-only rootfs and zero
# caps: config comes from env, the only writes are the log volume and /tmp.
user: "8000:8000"
read_only: true
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
tmpfs:
- /tmp:noexec,nosuid,nodev,size=16m
# No HTTP client in the image; check the listen socket via procfs (0x1F93=8083, 0A=LISTEN).
healthcheck:
test:
[
"CMD-SHELL",
"grep -qiE ':1F93 0+:0+ 0A' /proc/net/tcp /proc/net/tcp6 2>/dev/null || exit 1",
]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
# -------------------------------------------------------------- navidrome --
# Music streaming over the Subsonic API, which the desktop and iOS players
# speak, plus its own web player. The library is the plain-file music/ folder
# on the Storage Box; Navidrome indexes it and reads album art from the tags or
# a cover.* file beside the tracks. Built from the fork
# (https://github.com/thilo/navidrome), which adds per-user hiding of songs and
# albums behind an "Include Hidden" filter; its HIDDEN.md lists the edits to
# upstream. The tag is the upstream version plus a fork suffix. Built on the
# host; the versioned tag makes `up` build a new release.
navidrome:
build:
context: https://github.com/thilo/navidrome.git#v${NAVIDROME_VERSION}
args:
GIT_TAG: v${NAVIDROME_VERSION}
image: pc-navidrome:${NAVIDROME_VERSION}
container_name: pc-navidrome
restart: *restart
# Navidrome reaps its own children but not the healthcheck's orphans; see
# navidrome-sonic.
init: true
# Single Go process; ffmpeg runs as a child only when a client asks for a
# transcoded stream. Measured: 89 MiB anon peak over a full scan of 625
# tracks + 8 concurrent transcodes.
mem_limit: 256m
# Each ffmpeg starts threads per visible CPU. Measured: 4 concurrent transcodes
# peaked at 111 with 18 CPUs, and a cap of 64 failed one of them.
pids_limit: 256
# Distinct from the uid-1000 apps, for the same reason as Caddy's 1001.
user: "1002:1002"
environment:
# Library 1. Navidrome resets its path to this on every start; more libraries
# are added in the web UI as siblings under /music, never nested, since a
# nested one would index the same files twice.
ND_MUSICFOLDER: /music/${NAVIDROME_LIBRARY:?}
ND_DATAFOLDER: /data
# The watcher relies on inotify, which never fires for files that reach the
# box over SMB/SFTP from another machine. A scheduled quick scan picks them
# up instead; "Scan library" in the web UI does it on demand.
ND_SCANNER_WATCHERWAIT: "0"
ND_SCANNER_SCHEDULE: "@every 1h"
# Subsonic token auth needs the plaintext password, so Navidrome stores it
# encrypted. Unset, the key is a constant compiled into every build.
ND_PASSWORDENCRYPTIONKEY: ${NAVIDROME_PASSWORD_KEY}
ND_ENABLEINSIGHTSCOLLECTOR: "false"
# The sonic plugin (from navidrome-sonic) serves getSonicSimilarTracks and
# findSonicPath. As the first agent it also answers Instant Mix
# (getSimilarSongs2); for a track it has no answer for, the stock agents
# that follow it take over. It also writes each user's mood playlists.
ND_PLUGINS_ENABLED: "true"
ND_PLUGINS_FOLDER: /plugins
ND_AGENTS: sonic,deezer,lastfm,listenbrainz
# ND_EXTAUTH_TRUSTEDSOURCES stays unset. Setting it would let Navidrome read
# the client IP from X-Forwarded-For, but it also accepts a Remote-User
# header as a login from those sources — and every container on the proxy
# bridge would be one. Unset, the login limiter sees only Caddy's IP: one
# shared bucket, which for a single user is a stricter limit, not a looser one.
TZ: ${TZ}
volumes:
# :ro — Navidrome only reads the library; files are added on the box itself
# or by navidrome-upload.
- navidrome_music:/music:ro
- navidrome_data:/data
- navidrome_plugins:/plugins:ro
networks:
- proxy
- sonic
depends_on:
volume-init:
condition: service_completed_successfully
# Healthy means sonic.ndp is in place; plugins are discovered at startup.
navidrome-sonic:
condition: service_healthy
read_only: true
# noexec/nosuid/nodev: ffmpeg is on the rootfs; /tmp is only its scratch.
tmpfs:
- /tmp:noexec,nosuid,nodev,size=64m
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
# Also list the Storage Box CIFS mount so a wedged SMB session reads as
# unhealthy, not healthy-with-dead-storage. A listing, because the library has
# no fixed child path to stat. Recovery: scripts/mount-watchdog.sh.
healthcheck:
test:
[
"CMD-SHELL",
"curl -fsS --max-time 5 http://127.0.0.1:4533/ping >/dev/null 2>&1 && timeout 8 ls /music >/dev/null 2>&1",
]
interval: 30s
timeout: 15s
retries: 5
start_period: 30s
# ------------------------------------------------------- navidrome-sonic --
# Audio-similarity recommendations for Navidrome
# (https://github.com/thilo/navidrome-sonic). Each hour it walks the library,
# analyses every new or changed file (one thread) and keeps the results in
# SQLite on local disk; Navidrome's sonic plugin, which the image copies into
# navidrome_plugins, queries it over the internal network. Built on the host;
# the versioned tag makes `up` build a new release.
navidrome-sonic:
build: https://github.com/thilo/navidrome-sonic.git#v${NAVIDROME_SONIC_VERSION}
image: pc-navidrome-sonic:${NAVIDROME_SONIC_VERSION}
container_name: pc-navidrome-sonic
restart: *restart
# The Go sidecar runs as PID 1 and never reaps orphans; the healthcheck's
# busybox timeout leaves one per run, which would fill pids_limit.
init: true
# Measured: 76 MiB peak building the index at startup, 74 MiB analysing,
# 44 MiB idle.
mem_limit: 128m
# Measured peak: 14.
pids_limit: 32
# Below the default CPU weight under either of Docker's cpu_shares rescales
# (see immich-ml), so analysis yields to the other services and still uses
# idle CPU.
cpu_shares: 256
# Navidrome's uid: the music mount presents its files as 0700 to uid 1002.
user: "1002:1002"
volumes:
- navidrome_music:/music:ro
- navidrome_sonic_data:/data
- navidrome_plugins:/plugins
networks:
- sonic
depends_on:
volume-init:
condition: service_completed_successfully
read_only: true
tmpfs:
- /tmp:noexec,nosuid,nodev,size=16m
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
# Also list the Storage Box CIFS mount, as for navidrome.
healthcheck:
test:
[
"CMD-SHELL",
"wget -q -T 5 -O /dev/null http://127.0.0.1:8000/health && timeout 8 ls /music >/dev/null 2>&1",
]
interval: 30s
timeout: 15s
retries: 5
start_period: 30s
# ------------------------------------------------------ navidrome-upload --
# Upload page at <navidrome domain>/upload/
# (https://github.com/thilo/navidrome-upload): resumable uploads of tracks,
# folders or zips, which beets tags and files into a Navidrome library, for
# Navidrome admins with their existing login. Its README covers the login
# reuse and the upload checks. Built on the host; the versioned tag makes
# `up` build a new release.
navidrome-upload:
build: https://github.com/thilo/navidrome-upload.git#v${NAVIDROME_UPLOAD_VERSION}
image: pc-navidrome-upload:${NAVIDROME_UPLOAD_VERSION}
container_name: pc-navidrome-upload
restart: *restart
# Go reaps beets but not the healthcheck's orphans; see navidrome-sonic.
init: true
# Measured: 89 MiB peak importing a 40-track album zip, 6 MiB idle. The
# headroom is for MusicBrainz matching, which a test library can't exercise.
mem_limit: 256m
# Measured peak: 11, during an import.
pids_limit: 64
# Below the default weight, as for navidrome-sonic: an import yields to
# everything else.
cpu_shares: 256
# Writes the library, so it needs the music mount's uid.
user: "1002:1002"
volumes:
- navidrome_music:/music
- navidrome_upload_staging:/staging
# proxy: Caddy, Navidrome (login checks) and egress for MusicBrainz and
# cover art lookups.
networks:
- proxy
depends_on:
volume-init:
condition: service_completed_successfully
read_only: true
tmpfs:
- /tmp:noexec,nosuid,nodev,size=16m
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
# Also list the Storage Box CIFS mount, as for navidrome.
healthcheck:
test:
[
"CMD-SHELL",
"python3 -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health', timeout=5)\" && timeout 8 ls /music >/dev/null 2>&1",
]
interval: 30s
timeout: 15s
retries: 5
start_period: 30s