Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
525 lines (491 loc) · 23.3 KB
/
Copy pathdocker-compose.yml
File metadata and controls
525 lines (491 loc) · 23.3 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
services:
web:
container_name: caddy-proxy-manager-web
image: ghcr.io/caddyproxymanager/web:3.9.0
build:
context: .
dockerfile: docker/web/Dockerfile
args:
# Rootless; match your host user (id -u / id -g) to avoid permission issues.
PUID: ${PUID:-10001}
PGID: ${PGID:-10001}
restart: unless-stopped
ports:
- "3000:3000"
environment:
# A database-backed setting is passed as ${VAR:-}: its default is in the registry, and one
# set here would read as imported from the environment in setup.
# production enforces password security
NODE_ENV: production
# Required, and unique per instance. Generate with: openssl rand -base64 32
SESSION_SECRET: ${SESSION_SECRET:?ERROR - SESSION_SECRET is required}
# The value before a rotation; decrypt-only, and re-encrypted away at startup.
SESSION_SECRET_PREVIOUS: ${SESSION_SECRET_PREVIOUS:-}
# Only used with no agent. Caddy's name on the internal caddy-admin network; see caddy below.
CADDY_API_URL: ${CADDY_API_URL:-http://caddy-admin:2019}
# Pinned as admin.listen when no agent does it. Must match caddy's CADDY_ADMIN_LISTEN.
CADDY_ADMIN_LISTEN: caddy-admin:2019
# First-start default of a Settings field. Off only when sharing a Caddy this does not own.
CADDY_MONITOR_ENABLED: ${CADDY_MONITOR_ENABLED:-}
# Where generated certificates are written. Defaults to <workdir>/data/certs.
CERTS_DIRECTORY: ${CERTS_DIRECTORY:-}
BASE_URL: ${BASE_URL:-}
# Fields, not a URL: the interpolated password is never encoded, so a `/` in it would end the
# URL's authority early. Defaulted to the bundled service; override to use your own server.
POSTGRES_HOST: ${POSTGRES_HOST:-postgres}
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
POSTGRES_USER: ${POSTGRES_USER:-cpm}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?ERROR - POSTGRES_PASSWORD is required}
POSTGRES_DB: ${POSTGRES_DB:-cpm}
POSTGRES_SSL: ${POSTGRES_SSL:-}
# Overrides the fields, for options only a URL can say; percent-encode its password.
# `file:/app/data/cpm.db` is SQLite. A pre-3.0 file is migrated in-app, not pointed at here.
DATABASE_URL: ${DATABASE_URL:-}
# The real default, not `${VAR:-}`: Number("") is 0.
DATABASE_POOL_MAX: ${DATABASE_POOL_MAX:-10}
NEXTAUTH_URL: ${BASE_URL:-}
# Renames the app in the sidebar, login card, and page titles.
APP_NAME: ${APP_NAME:-}
ACCENT_COLOR: ${ACCENT_COLOR:-}
# Seeds the managed dashboard host once, at the end of setup (default: BASE_URL's hostname);
# after that the stored setting wins. Caddy reads it for its placeholder site.
DASHBOARD_DOMAIN: ${DASHBOARD_DOMAIN:-}
# Users without an icon fall back to Gravatar, which their browser fetches directly.
# Set false to disable it and lock the Settings toggle.
AVATAR_GRAVATAR: ${AVATAR_GRAVATAR:-}
# Simulate Caddy and the agent instead of configuring anything. See .env.example.
DEMO_MODE: ${DEMO_MODE:-false}
# Blank: first-run setup creates the admin in the browser. Both set seeds one at startup;
# in production the password then needs 12+ chars with upper, lower, digit and special.
ADMIN_USERNAME: ${ADMIN_USERNAME:-}
ADMIN_PASSWORD: ${ADMIN_PASSWORD:-}
# Let new users sign themselves up.
AUTH_ALLOW_SELF_REGISTRATION: ${AUTH_ALLOW_SELF_REGISTRATION:-}
AUTH_ALLOW_OAUTH_REGISTRATION: ${AUTH_ALLOW_OAUTH_REGISTRATION:-}
# When false, OAuth-created accounts are user/active whatever the IdP's claims say.
AUTH_ALLOW_OAUTH_ROLE_FROM_CLAIMS: ${AUTH_ALLOW_OAUTH_ROLE_FROM_CLAIMS:-}
# OIDC-only: no local accounts and no bootstrap admin. Enable only once OAuth works.
AUTH_DISABLE_LOCAL_USERS: ${AUTH_DISABLE_LOCAL_USERS:-}
# Only behind a proxy that rewrites Host, and only when BASE_URL cannot cover it.
AUTH_TRUST_HOST: ${AUTH_TRUST_HOST:-}
# Passkey autofill on the sign-in screens; off, only the passkey button starts one.
AUTH_PASSKEY_AUTOFILL: ${AUTH_PASSKEY_AUTOFILL:-}
# Force a reset for pre-argon2id bcrypt hashes. Setting it locks the Settings toggle.
AUTH_REQUIRE_PASSWORD_CHANGE_ON_LEGACY_HASH: ${AUTH_REQUIRE_PASSWORD_CHANGE_ON_LEGACY_HASH:-}
# Better Auth request rate limiting, and the separate login throttle.
AUTH_RATE_LIMIT_ENABLED: ${AUTH_RATE_LIMIT_ENABLED:-}
AUTH_RATE_LIMIT_WINDOW: ${AUTH_RATE_LIMIT_WINDOW:-}
AUTH_RATE_LIMIT_MAX: ${AUTH_RATE_LIMIT_MAX:-}
LOGIN_MAX_ATTEMPTS: ${LOGIN_MAX_ATTEMPTS:-}
LOGIN_WINDOW_MS: ${LOGIN_WINDOW_MS:-}
LOGIN_BLOCK_MS: ${LOGIN_BLOCK_MS:-}
ACCOUNT_LOCK_ENABLED: ${ACCOUNT_LOCK_ENABLED:-}
ACCOUNT_LOCK_FREE_FAILURES: ${ACCOUNT_LOCK_FREE_FAILURES:-}
ACCOUNT_LOCK_BASE_DELAY_MS: ${ACCOUNT_LOCK_BASE_DELAY_MS:-}
ACCOUNT_LOCK_MAX_DELAY_MS: ${ACCOUNT_LOCK_MAX_DELAY_MS:-}
ACCOUNT_LOCK_DISABLE_ENABLED: ${ACCOUNT_LOCK_DISABLE_ENABLED:-}
ACCOUNT_LOCK_DISABLE_AFTER: ${ACCOUNT_LOCK_DISABLE_AFTER:-}
ACCESS_REVIEW_CONFIRM_REVOCATIONS: ${ACCESS_REVIEW_CONFIRM_REVOCATIONS:-}
ACCESS_REVIEW_REMINDER_DAYS: ${ACCESS_REVIEW_REMINDER_DAYS:-}
# Optional OAuth2/OIDC - Authentik, Authelia, Keycloak, and similar.
OAUTH_ENABLED: ${OAUTH_ENABLED:-false}
OAUTH_PROVIDER_NAME: ${OAUTH_PROVIDER_NAME:-OAuth2}
OAUTH_CLIENT_ID: ${OAUTH_CLIENT_ID:-}
OAUTH_CLIENT_SECRET: ${OAUTH_CLIENT_SECRET:-}
OAUTH_ISSUER: ${OAUTH_ISSUER:-}
OAUTH_AUTHORIZATION_URL: ${OAUTH_AUTHORIZATION_URL:-}
OAUTH_TOKEN_URL: ${OAUTH_TOKEN_URL:-}
OAUTH_USERINFO_URL: ${OAUTH_USERINFO_URL:-}
OAUTH_ALLOW_AUTO_LINKING: ${OAUTH_ALLOW_AUTO_LINKING:-false}
OAUTH_SCOPES: ${OAUTH_SCOPES:-}
# Name each role's groups (comma-separated, any one grants it), or set a prefix to derive
# <prefix>Admin, <prefix>User and <prefix>Viewer.
OAUTH_ROLE_MAPPING: ${OAUTH_ROLE_MAPPING:-false}
OAUTH_GROUPS_CLAIM: ${OAUTH_GROUPS_CLAIM:-}
OAUTH_GROUP_PREFIX: ${OAUTH_GROUP_PREFIX:-}
OAUTH_ADMIN_GROUP: ${OAUTH_ADMIN_GROUP:-}
OAUTH_USER_GROUP: ${OAUTH_USER_GROUP:-}
OAUTH_VIEWER_GROUP: ${OAUTH_VIEWER_GROUP:-}
OAUTH_OPERATOR_GROUP: ${OAUTH_OPERATOR_GROUP:-}
OAUTH_DEFAULT_ROLE: ${OAUTH_DEFAULT_ROLE:-}
OAUTH_SYNC_GROUPS: ${OAUTH_SYNC_GROUPS:-false}
# First-start defaults of Settings fields. A fork sets the repository to its own namespace.
UPDATE_CHECK_ENABLED: ${UPDATE_CHECK_ENABLED:-}
UPDATE_CHECK_PRERELEASES: ${UPDATE_CHECK_PRERELEASES:-}
UPDATE_IMAGE_REPOSITORY: ${UPDATE_IMAGE_REPOSITORY:-}
OFFLINE_MODE: ${OFFLINE_MODE:-}
HOST_HISTORY_KEEP_REVISIONS: ${HOST_HISTORY_KEEP_REVISIONS:-}
HOST_HISTORY_KEEP_DAYS: ${HOST_HISTORY_KEEP_DAYS:-}
AUDIT_LOG_KEEP_DAYS: ${AUDIT_LOG_KEEP_DAYS:-}
# Settings toggles; the agent starts ClickHouse to match, so these matter only for a first
# start or a deployment with no agent. Unset decides from whether the credentials are set.
ANALYTICS_ENABLED: ${ANALYTICS_ENABLED:-}
GEOIP_ENABLED: ${GEOIP_ENABLED:-}
CLICKHOUSE_URL: ${CLICKHOUSE_URL:-}
CLICKHOUSE_USER: ${CLICKHOUSE_USER:-}
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-}
CLICKHOUSE_DB: ${CLICKHOUSE_DB:-}
CLICKHOUSE_RETENTION_DAYS: ${CLICKHOUSE_RETENTION_DAYS:-}
# Prefer Settings -> GeoIP, where the licence key is encrypted at rest.
GEOIPUPDATE_ACCOUNT_ID: ${GEOIPUPDATE_ACCOUNT_ID:-}
GEOIPUPDATE_LICENSE_KEY: ${GEOIPUPDATE_LICENSE_KEY:-}
GEOIP_UPDATE_INTERVAL_HOURS: ${GEOIP_UPDATE_INTERVAL_HOURS:-}
# Settings -> Email. Unset SMTP_ENABLED turns email on once a server is named. Prefer
# Settings for the password, where it is encrypted at rest.
SMTP_ENABLED: ${SMTP_ENABLED:-}
SMTP_HOST: ${SMTP_HOST:-}
SMTP_PORT: ${SMTP_PORT:-}
SMTP_SECURITY: ${SMTP_SECURITY:-}
SMTP_USERNAME: ${SMTP_USERNAME:-}
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
SMTP_FROM: ${SMTP_FROM:-}
SMTP_FROM_NAME: ${SMTP_FROM_NAME:-}
EMAIL_ALERT_RECIPIENTS: ${EMAIL_ALERT_RECIPIENTS:-}
CERTIFICATE_EXPIRY_ALERT_DAYS: ${CERTIFICATE_EXPIRY_ALERT_DAYS:-}
NOTIFY_ACCOUNT_DISABLED: ${NOTIFY_ACCOUNT_DISABLED:-}
NOTIFY_ADMIN_LOCKED: ${NOTIFY_ADMIN_LOCKED:-}
NOTIFY_ADMIN_ADDED: ${NOTIFY_ADMIN_ADDED:-}
NOTIFY_AGENT_OFFLINE: ${NOTIFY_AGENT_OFFLINE:-}
NOTIFY_AGENT_OFFLINE_MINUTES: ${NOTIFY_AGENT_OFFLINE_MINUTES:-}
NOTIFY_UPSTREAM_ERRORS: ${NOTIFY_UPSTREAM_ERRORS:-}
NOTIFY_UPSTREAM_ERROR_COUNT: ${NOTIFY_UPSTREAM_ERROR_COUNT:-}
NOTIFY_UPSTREAM_ERROR_MINUTES: ${NOTIFY_UPSTREAM_ERROR_MINUTES:-}
NOTIFY_CADDY_APPLY: ${NOTIFY_CADDY_APPLY:-}
NOTIFY_AGENT_PROBLEMS: ${NOTIFY_AGENT_PROBLEMS:-}
NOTIFY_GEOIP_FAILED: ${NOTIFY_GEOIP_FAILED:-}
NOTIFY_CRS_PLUGIN_DISABLED: ${NOTIFY_CRS_PLUGIN_DISABLED:-}
NOTIFY_UPDATE_AVAILABLE: ${NOTIFY_UPDATE_AVAILABLE:-}
NOTIFY_BACKUP_FAILED: ${NOTIFY_BACKUP_FAILED:-}
NOTIFY_AUDIT_SINK_FAILED: ${NOTIFY_AUDIT_SINK_FAILED:-}
NOTIFY_ACCESS_REVIEWS: ${NOTIFY_ACCESS_REVIEWS:-}
NOTIFY_CHANGE_APPROVALS: ${NOTIFY_CHANGE_APPROVALS:-}
NOTIFY_CHANNEL_FAILING: ${NOTIFY_CHANNEL_FAILING:-}
NOTIFY_DISABLED_ACCOUNT_OWNER: ${NOTIFY_DISABLED_ACCOUNT_OWNER:-}
# First-start defaults of Settings fields.
FORWARD_AUTH_INTERNAL_URL: ${FORWARD_AUTH_INTERNAL_URL:-}
FORWARD_AUTH_ALLOWED_PORTS: ${FORWARD_AUTH_ALLOWED_PORTS:-}
FORWARD_AUTH_SEQUENTIAL_USER_IDS: ${FORWARD_AUTH_SEQUENTIAL_USER_IDS:-}
CADDY_BUILD_TIMEOUT: "${CADDY_BUILD_TIMEOUT:-}"
# Variables that override a stored value, for getting back into a locked-out instance.
SETTINGS_ENV_OVERRIDE: ${SETTINGS_ENV_OVERRIDE:-}
# Pre-3.0 migration: which database the setup flow offers, and when legacy-key secrets expire.
LEGACY_SQLITE_PATH: ${LEGACY_SQLITE_PATH:-}
LEGACY_KEY_CUTOFF_DATE: ${LEGACY_KEY_CUTOFF_DATE:-}
group_add:
- "${CADDY_GID:-10000}" # caddy's GID, so web can write /logs
volumes:
# Also holds the GeoLite2 databases, under geoip/.
- caddy-manager-data:/app/data
# The agent reads these; kept because an operator reaching for the logs expects them here.
- caddy-logs:/logs
- acme-ca:/acme-ca
# Not on Caddy: the agent starts it after pairing, which needs this controller up.
depends_on:
postgres:
condition: service_healthy
clickhouse:
condition: service_healthy
required: false
# musl waits out its whole resolver timeout (5s) on the SERVFAIL Docker's DNS answers when no
# upstream is reachable, as for caddy-admin before Caddy runs on a host with no route out. The
# first timeout listed wins, so an override changing it needs `dns_opt: !override [...]`.
dns_opt:
- timeout:2
- attempts:2
networks:
# So Caddy can reach the dashboard and forward auth, and for egress.
- caddy-network
- caddy-admin
- database
- analytics
healthcheck:
test: ["CMD", "/app/cpm-server", "--healthcheck"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
caddy:
container_name: caddy-proxy-manager-caddy
# An image you build yourself, with the agent's CADDY_BUILD_MODE=external. See the README.
image: ${CADDY_IMAGE:-ghcr.io/caddyproxymanager/caddy:3.9.0}
build:
context: .
dockerfile: docker/caddy/Dockerfile
args:
# Match your host user to avoid permission issues: id -u / id -g
PUID: ${PUID:-10000}
PGID: ${PGID:-10000}
# Profiled so `docker compose up` skips it: the agent starts it once paired, so an unpaired
# host does not answer 80 and 443, and again on its own restart before the controller answers.
profiles: ["caddy"]
restart: unless-stopped
ports:
- "80:80"
- "80:80/udp"
- "443:443"
- "443:443/udp"
# No 2019: the admin API binds only on the internal caddy-admin network, which cannot publish.
# Metrics for Prometheus/Grafana, once enabled in Settings.
# - "9090:9090"
environment:
DASHBOARD_DOMAIN: ${DASHBOARD_DOMAIN:-caddyproxymanager.com}
# The admin bind until the first config: a name only caddy-admin resolves. The agent's
# CADDY_ADMIN_LISTEN and the healthcheck match it.
CADDY_ADMIN_LISTEN: caddy-admin:2019
volumes:
- caddy-data:/data
- caddy-config:/config
# A bind mount here needs r as well as w+x for caddy, or log rotation silently stops pruning
# and the disk fills: chgrp <PGID> <host-dir> && chmod 2770 <host-dir>
- caddy-logs:/logs
# The agent's GeoIP copy. Only geoip/, read-only: the rest of that volume holds the agent's
# pairing secrets. A volume subpath needs Docker Engine 26+.
- type: volume
source: agent-data
target: /usr/share/GeoIP
read_only: true
volume:
subpath: geoip
- acme-ca:/acme-ca:ro
networks:
# Where users attach the containers Caddy proxies to.
caddy-network: {}
# The alias exists here alone, so an upstream on caddy-network cannot reach the API.
caddy-admin:
aliases:
- caddy-admin
# The bouncer's way to the managed crowdsec; see there.
crowdsec: {}
healthcheck:
# The bound name: the admin API does not listen on loopback.
test: ["CMD", "wget", "--quiet", "--tries=1", "-O", "/dev/null", "http://caddy-admin:2019/config/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
# Not a security boundary: it matches URL prefixes and never sees a body, so whatever drives the
# agent is root on this host. The real control is the agent validating input. See SECURITY.md.
docker-socket-proxy:
container_name: caddy-proxy-manager-docker-proxy
image: tecnativa/docker-socket-proxy:v0.5.0@sha256:1f5038b54f06c3e18422902cf00ba21803d1c97805aae032e5e6673d532d3459
restart: unless-stopped
environment:
# All used by the agent's compose: networks are inspected on every up, and a managed
# service's first start creates its volume and pulls its image.
CONTAINERS: 1
POST: 1
NETWORKS: 1
VOLUMES: 1
IMAGES: 1
SECRETS: 0
# BuildKit, for "Rebuild Caddy"; piped unfiltered once matched (see the mounted config).
# Both 0 disables only that button: pair it with the agent's CADDY_BUILD_MODE=external.
GRPC: 1
SESSION: 1
# On in the image's defaults; nothing the agent runs reads the event stream.
EVENTS: 0
# BUILD is the legacy builder, which cannot build Caddy's image.
BUILD: 0
EXEC: 0
SWARM: 0
AUTH: 0
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
# Upstream's config plus a TCP route for GRPC and SESSION, which its HTTP mode cannot pass.
- ./socket-proxy-haproxy.cfg.template:/usr/local/etc/haproxy/haproxy.cfg.template:ro
networks:
- socket-proxy
agent:
container_name: caddy-proxy-manager-agent
image: ghcr.io/caddyproxymanager/agent:3.9.0
# It allows stopping Caddy 40s on exit; Docker's default 10s would kill it part-way.
stop_grace_period: 1m
build:
context: .
dockerfile: docker/agent/Dockerfile
args:
# Not PUID/PGID, which already mean two different users to web and caddy.
PUID: ${AGENT_PUID:-10002}
PGID: ${AGENT_PGID:-10002}
restart: unless-stopped
environment:
DATA_DIR: /data
# Read-only: the bootstrap token, and once, on upgrade, state agents kept there before.
CONTROLLER_DATA_DIR: /controller-data
COMPOSE_DIR: /compose
AGENT_MODE: ${AGENT_MODE:-standalone}
# An agent on another host needs the controller's reachable address, and pairs with
# `docker exec -it <agent> cpm-agent --pair --host <that address> --code <code>`.
CONTROLLER_URL: ${CONTROLLER_URL:-http://web:3000}
# Plain http to a non-private address is refused: pairing sends the shared secret over it.
CONTROLLER_ALLOW_INSECURE_HTTP: ${CONTROLLER_ALLOW_INSECURE_HTTP:-false}
CADDY_API_URL: ${CADDY_API_URL:-http://caddy-admin:2019}
# The controller's admin block binds every interface, caddy-network included, so the agent
# pins this into every config it forwards. Must match caddy's CADDY_ADMIN_LISTEN.
CADDY_ADMIN_LISTEN: caddy-admin:2019
CADDY_BUILD_TIMEOUT: "${CADDY_BUILD_TIMEOUT:-1800}"
# `external`: never build Caddy's image, only load the one you built (CADDY_IMAGE below).
CADDY_BUILD_MODE: ${CADDY_BUILD_MODE:-agent}
# Generous: clickhouse's first start pulls the image.
SERVICE_START_TIMEOUT: "${SERVICE_START_TIMEOUT:-900}"
# A host directory certificates may be read from, as the daemon sees it; unset is off.
CERT_FILES_HOST_DIR: ${CERT_FILES_HOST_DIR:-}
# The files your own compose reads, so a recreate keeps an override kept elsewhere.
COMPOSE_FILE: ${COMPOSE_FILE:-}
COMPOSE_PATH_SEPARATOR: ${COMPOSE_PATH_SEPARATOR:-}
DOCKER_HOST: tcp://docker-socket-proxy:2375
# The agent never reads .env (it holds the secrets), so what caddy and clickhouse
# interpolate, including from an override file, is forwarded here.
PUID: ${PUID:-}
PGID: ${PGID:-}
DASHBOARD_DOMAIN: ${DASHBOARD_DOMAIN:-}
CADDY_IMAGE: ${CADDY_IMAGE:-}
CLICKHOUSE_DB: ${CLICKHOUSE_DB:-}
CLICKHOUSE_USER: ${CLICKHOUSE_USER:-}
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-}
group_add:
# Caddy's, to read its logs and truncate the WAF audit log. Must match caddy's PGID.
- "${CADDY_GID:-10000}"
# The controller's, to read the bootstrap token. Must match web's PGID.
- "${CONTROLLER_GID:-10001}"
volumes:
# Its database, socket and compose overrides, and the GeoIP databases Caddy mounts from here.
- agent-data:/data
- caddy-manager-data:/controller-data:ro
# The directory: a single-file mount of a missing override creates a directory on the host.
# .env stays unread (keep it 0600), but the agent can read anything else others can.
- .:/compose:ro
- caddy-logs:/logs
# Never on Caddy: the agent is what starts it, so waiting on it deadlocks.
depends_on:
docker-socket-proxy:
condition: service_started
# As for web: a failed lookup costs 2s rather than 5.
dns_opt:
- timeout:2
- attempts:2
networks:
- socket-proxy
# Caddy's admin API, which it proxies for, and the controller.
- caddy-admin
# Egress, for a controller on another host.
- caddy-network
# No profile, so the default stack has a database without setting a variable. Unpublished on
# purpose: publishing 5432 is how a database ends up on the internet.
postgres:
container_name: caddy-proxy-manager-postgres
image: postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-cpm}
POSTGRES_USER: ${POSTGRES_USER:-cpm}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?ERROR - POSTGRES_PASSWORD is required}
# The parent directory, as 18+ expects (the cluster is in 18/docker). A 17 cluster at the root
# refuses to start; see "Upgrading from PostgreSQL 17" in the README.
volumes:
- postgres-data:/var/lib/postgresql
networks:
- database
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-cpm} -d ${POSTGRES_DB:-cpm}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# The agent passes `--profile clickhouse` when Settings -> Analytics asks for it;
# COMPOSE_PROFILES is needed only with no agent.
clickhouse:
container_name: caddy-proxy-manager-clickhouse
image: clickhouse/clickhouse-server:26.9.12.8-alpine@sha256:d94d23b5cf0a0a0433a1b5b909f8900bf126783e8c3c7b806add464cc0604794
profiles: [clickhouse]
restart: unless-stopped
environment:
CLICKHOUSE_DB: ${CLICKHOUSE_DB:-analytics}
CLICKHOUSE_USER: ${CLICKHOUSE_USER:-cpm}
# Not `:?`: interpolation runs on every invocation naming the project, and a deployment may
# keep this in the database. The controller refuses to enable analytics without one.
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-}
# No CREATE USER, GRANT or ROLE: the controller needs only table DDL, and nothing but the
# controller holds this account.
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 0
volumes:
- clickhouse-data:/var/lib/clickhouse
- ./clickhouse-low-disk-write.yml:/etc/clickhouse-server/config.d/low-disk-write.yml:ro
networks:
- analytics
healthcheck:
# Expanded by the container's shell, so `docker inspect` does not print the password.
test: ["CMD-SHELL", "clickhouse-client --user \"$$CLICKHOUSE_USER\" --password \"$$CLICKHOUSE_PASSWORD\" --query 'SELECT 1'"]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
ulimits:
nofile:
soft: 262144
hard: 262144
# Settings -> CrowdSec in managed mode: the agent passes `--profile crowdsec` and the bouncer key
# the controller generated. For the bundled agent's host only.
crowdsec:
container_name: caddy-proxy-manager-crowdsec
image: crowdsecurity/crowdsec:v1.8.1@sha256:0f2523fa61ef507f15d953045cface490cc880670c62f2755ced17524107f71a
profiles: [crowdsec]
restart: unless-stopped
environment:
# AppSec's too, always: acquis.yaml listens for it, so switching it on needs no recreate.
COLLECTIONS: crowdsecurity/caddy crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules
# Not `:?`, for the same reason as CLICKHOUSE_PASSWORD. Registered once, on the first start.
BOUNCER_KEY_caddy: ${CROWDSEC_BOUNCER_KEY:-}
# Off unless Settings shares signals: the online API sends CrowdSec every attacker address.
DISABLE_ONLINE_API: ${CROWDSEC_DISABLE_ONLINE_API:-true}
volumes:
- crowdsec-data:/var/lib/crowdsec/data
- crowdsec-config:/etc/crowdsec
- caddy-logs:/logs:ro
- ./crowdsec-acquis.yaml:/etc/crowdsec/acquis.d/cpm.yaml:ro
networks:
# Not caddy-network, where an upstream could reach the LAPI. Not internal either: the hub and
# the online API are on the internet. The alias is unlikely to be taken by a user container,
# which, sharing a network with Caddy, would otherwise be sent the bouncer key.
crowdsec:
aliases:
- cpm-crowdsec
healthcheck:
test: ["CMD", "cscli", "lapi", "status"]
interval: 30s
timeout: 10s
retries: 3
# The first start downloads the hub collections.
start_period: 120s
networks:
caddy-network:
driver: bridge
# Otherwise IPv4 only, and an IPv6 upstream has no route.
enable_ipv6: true
# Internal, like the rest: nothing on them needs egress, and caddy-network cannot reach them.
caddy-admin:
driver: bridge
internal: true
database:
driver: bridge
internal: true
analytics:
driver: bridge
internal: true
socket-proxy:
driver: bridge
internal: true
# Caddy and the managed crowdsec only. It has egress, which Caddy already has on caddy-network.
crowdsec:
driver: bridge
volumes:
caddy-manager-data:
agent-data:
caddy-data:
caddy-config:
caddy-logs:
clickhouse-data:
crowdsec-data:
crowdsec-config:
postgres-data:
acme-ca: