-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
149 lines (142 loc) · 4.84 KB
/
Copy pathdocker-compose.yml
File metadata and controls
149 lines (142 loc) · 4.84 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
services:
# ── Frontend (nginx — serves React SPA + proxies API) ───────────────────────
# Default mode: exposes HTTPS on APP_PORT and HTTP on APP_HTTP_PORT.
# HTTP is intended for use behind a reverse proxy that terminates TLS.
# Production mode (--profile https): Caddy handles TLS instead (see below)
frontend:
build:
context: .
dockerfile: frontend/Dockerfile
args:
VITE_BUILD_SHA: ${GIT_SHA:-dev}
VITE_EMAIL_DIV_RENDER: ${VITE_EMAIL_DIV_RENDER:-false}
NGINX_BASE: ${NGINX_BASE:-nginx:alpine}
container_name: mailflow-frontend
restart: unless-stopped
ports:
- "${APP_PORT:-443}:443"
- "${APP_HTTP_PORT:-80}:80"
volumes:
- ./certs:/etc/nginx/ssl
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -qO/dev/null http://127.0.0.1:80/ || exit 1"]
interval: 15s
timeout: 5s
retries: 3
start_period: 20s
networks:
- mailflow
# ── Backend API ──────────────────────────────────────────────────────────────
backend:
build:
context: .
dockerfile: backend/Dockerfile
args:
BUILD_SHA: ${GIT_SHA:-dev}
container_name: mailflow-backend
restart: unless-stopped
environment:
NODE_ENV: production
PORT: 3000
SESSION_SECRET: ${SESSION_SECRET}
APP_URL: ${APP_URL:-}
FRONTEND_URL: ${APP_URL:-}
DB_HOST: ${DB_HOST:-postgres}
DB_PORT: ${DB_PORT:-5432}
DB_NAME: ${DB_NAME:-mailflow}
DB_USER: ${DB_USER:-mailflow}
DB_PASSWORD: ${DB_PASSWORD}
REDIS_URL: ${REDIS_URL:-redis://redis:6379}
ENCRYPTION_KEY: ${ENCRYPTION_KEY:-}
VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY:-}
VAPID_PRIVATE_KEY: ${VAPID_PRIVATE_KEY:-}
VAPID_SUBJECT: ${VAPID_SUBJECT:-}
IMAP_MAX_PERSISTENT_PER_HOST: ${IMAP_MAX_PERSISTENT_PER_HOST:-}
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:3000/api/health || exit 1"]
interval: 15s
timeout: 5s
retries: 3
start_period: 30s
networks:
- mailflow
# ── PostgreSQL ───────────────────────────────────────────────────────────────
postgres:
image: postgres:16-alpine
container_name: mailflow-postgres
restart: unless-stopped
# PUID/PGID default to 0:0 (root), identical to the image's normal behaviour.
# Set them (e.g. 99:100 on Unraid) only when bind-mounting POSTGRES_DATA to a host
# share, and chown that share to the same uid:gid first.
user: "${PUID:-0}:${PGID:-0}"
environment:
POSTGRES_DB: ${DB_NAME:-mailflow}
POSTGRES_USER: ${DB_USER:-mailflow}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- ${POSTGRES_DATA:-postgres_data}:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U mailflow -d mailflow"]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
networks:
- mailflow
# ── Redis (sessions + caching) ───────────────────────────────────────────────
redis:
image: redis:7-alpine
container_name: mailflow-redis
restart: unless-stopped
user: "${PUID:-0}:${PGID:-0}"
command: redis-server --save 60 1 --loglevel warning
volumes:
- ${REDIS_DATA:-redis_data}:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
start_period: 10s
networks:
- mailflow
# ── Caddy (automatic HTTPS via Let's Encrypt — production only) ──────────────
# Use docker-compose.https.yml to avoid the port conflict with the frontend:
# docker compose -f docker-compose.yml -f docker-compose.https.yml --profile https up -d --build
# Requires DOMAIN, ACME_EMAIL, and APP_URL to be set in .env, and ports 80/443 to be open.
caddy:
profiles: ["https"]
image: caddy:2-alpine
container_name: mailflow-caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
environment:
DOMAIN: ${DOMAIN:-localhost}
ACME_EMAIL: ${ACME_EMAIL:-}
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- frontend
networks:
- mailflow
volumes:
postgres_data:
redis_data:
caddy_data:
caddy_config:
networks:
mailflow:
driver: bridge