Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
264 lines (249 loc) · 10 KB
/
Copy pathdocker-compose.yml
File metadata and controls
264 lines (249 loc) · 10 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
version: '3.8'
# ==========================================
# OpenNVR - Docker Compose Configuration
# ==========================================
#
# SETUP INSTRUCTIONS:
# 1. Copy .env.example to .env
# 2. Generate secrets: ./scripts/generate-secrets.ps1 (or .sh)
# 3. Update .env with generated secrets
# 4. Run: docker compose up -d
#
# IMPORTANT:
# - All secrets are loaded from .env file (NOT hardcoded)
# - Never commit .env to version control!
#
# 🚨 CHOOSE YOUR NETWORK MODE BASED ON YOUR OS 🚨
# Choose ONE mode below and comment/uncomment sections labeled as such in this file.
#
# 👉 OPTION 1: BRIDGE MODE (Default for Windows / Mac)
# - Best for development on Windows and Mac.
# - Look for `# [WINDOWS/MAC] BRIDGE MODE:` lines in this file.
# - UNCOMMENT the lines under those sections (ports, networks, bridge env vars).
#
# 👉 OPTION 2: HOST MODE (Required for Linux / ONVIF Discovery)
# - Required for ONVIF camera discovery via UDP broadcast cache on Linux.
# - Look for `# [LINUX] HOST MODE:` lines in this file.
# - UNCOMMENT the lines under those sections (network_mode: host, linux env vars).
# - COMMENT OUT all BRIDGE MODE lines.
#
# 💡 TIP: Use the smart launcher scripts instead of this file directly:
# - Linux/macOS: ./start.sh build
# - Windows: .\start.ps1 build
# ==========================================
services:
# ==========================================
# 1. DATABASE (PostgreSQL)
# ==========================================
db:
image: postgres:15-alpine
container_name: opennvr_db
restart: unless-stopped
# ----------------------------------------------------
# [LINUX] HOST MODE: Uncomment ONE line below
# network_mode: host
# ----------------------------------------------------
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
# [LINUX] HOST MODE: PostgreSQL binds to port 5432 on host
# PGPORT: 5432
volumes:
- opennvr_db_data:/var/lib/postgresql/data
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment lines below
networks:
- sentinel_internal
# ----------------------------------------------------
healthcheck:
# [LINUX] HOST MODE: Uncomment line below
# test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB} -h 127.0.0.1"]
# [WINDOWS/MAC] BRIDGE MODE: Uncomment line below
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
# ==========================================
# 2. MEDIAMTX (Streaming Server)
# ==========================================
mediamtx:
# Use custom MediaMTX image with curl/wget for webhooks and health checks
image: abhishekch1112/opennvr-mediamtx:latest
container_name: opennvr_mediamtx
restart: unless-stopped
# ----------------------------------------------------
# [LINUX] HOST MODE: Uncomment ONE line below
# network_mode: host
# ----------------------------------------------------
depends_on:
db:
condition: service_healthy
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment lines below
ports:
- "127.0.0.1:8554:8554" # RTSP
- "127.0.0.1:8888:8888" # HLS
- "127.0.0.1:8889:8889" # WebRTC Signaling
- "127.0.0.1:8189:8189/tcp" # WebRTC ICE TCP
- "127.0.0.1:8189:8189/udp" # WebRTC ICE UDP
- "127.0.0.1:9997:9997" # API/Metrics
- "127.0.0.1:9996:9996" # Playback API
# ----------------------------------------------------
volumes:
# Mount Docker-specific mediamtx configuration
- ./mediamtx.docker.yml:/mediamtx.yml:ro
# Mount recordings directory (configurable via .env file)
- ${RECORDINGS_PATH:-/home/ubuntu/recordings}:/app/recordings
environment:
# MediaMTX webhook configuration
- MEDIAMTX_SECRET=${MEDIAMTX_SECRET}
# ----------------------------------------------------
# [LINUX] HOST MODE: Uncomment ONE line below
# - BACKEND_HOST=127.0.0.1
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment ONE line below
- BACKEND_HOST=${BACKEND_HOST:-opennvr_core}
# ----------------------------------------------------
- BACKEND_PORT=${BACKEND_PORT:-8000}
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment lines below
networks:
- sentinel_internal
# ----------------------------------------------------
# Health check using curl (available in custom opennvr-mediamtx image)
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:9997/v3/paths/list"]
interval: 30s
timeout: 10s
start_period: 10s
retries: 3
# ==========================================
# 3. CORE APPLICATION (Backend + Frontend + Kai-C)
# ==========================================
opennvr-core:
# Use pre-built image from Docker Hub (Production)
# image: abhishekch1112/opennvr-core:latest
# OR build locally (Development)
build:
context: .
dockerfile: Dockerfile
container_name: opennvr_core
restart: unless-stopped
# ----------------------------------------------------
# [LINUX] HOST MODE: Uncomment ONE line below
# network_mode: host
# ----------------------------------------------------
depends_on:
db:
condition: service_healthy
mediamtx:
condition: service_healthy
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment lines below
ports:
- "127.0.0.1:8000:8000" # API
# ----------------------------------------------------
volumes:
- shared_frames:/app/AI-adapters/AIAdapters/frames
# Mount project root for configuration access
- .:/app/host-root
# Mount recordings directory (configurable via .env file)
- ${RECORDINGS_PATH:-/home/ubuntu/recordings}:/app/recordings
environment:
# ----------------------------------------------------
# [LINUX] HOST MODE: Uncomment lines below
# - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:5432/${POSTGRES_DB}
# - MEDIAMTX_BASE_URL=http://127.0.0.1:8889
# - MEDIAMTX_ADMIN_API=http://127.0.0.1:9997/v3
# - MEDIAMTX_HLS_URL=http://127.0.0.1:8888
# - MEDIAMTX_RTSP_URL=rtsp://127.0.0.1:8554
# - MEDIAMTX_PLAYBACK_URL=http://127.0.0.1:9996
# - KAI_C_URL=http://127.0.0.1:8100
# ----------------------------------------------------
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment lines below
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
- MEDIAMTX_BASE_URL=http://mediamtx:8889
- MEDIAMTX_ADMIN_API=http://mediamtx:9997/v3
- MEDIAMTX_HLS_URL=http://mediamtx:8888
- MEDIAMTX_RTSP_URL=rtsp://mediamtx:8554
- MEDIAMTX_PLAYBACK_URL=http://mediamtx:9996
- KAI_C_URL=http://127.0.0.1:8100
# ----------------------------------------------------
# External URLs for browser access
- MEDIAMTX_EXTERNAL_BASE_URL=http://127.0.0.1:8889
- MEDIAMTX_EXTERNAL_HLS_URL=http://127.0.0.1:8888
- MEDIAMTX_EXTERNAL_PLAYBACK_URL=http://127.0.0.1:9996
# Path mapping configuration for volume mounts
- RECORDINGS_HOST_BASE=${RECORDINGS_PATH}
- RECORDINGS_CONTAINER_BASE=/app/recordings
- RECORDINGS_BASE_PATH=/app/recordings
# Security secrets - loaded from .env file
- SECRET_KEY=${SECRET_KEY}
- CREDENTIAL_ENCRYPTION_KEY=${CREDENTIAL_ENCRYPTION_KEY}
- INTERNAL_API_KEY=${INTERNAL_API_KEY}
- MEDIAMTX_SECRET=${MEDIAMTX_SECRET}
# AI Adapter URL (for Kai-C → ai-adapters routing via supervisord)
- ADAPTER_URL=http://opennvr_ai:9100
# Application settings
- HOST=${HOST:-0.0.0.0}
- DEBUG=${DEBUG:-False}
- LOG_LEVEL=${LOG_LEVEL:-INFO}
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment lines below
networks:
- sentinel_internal
# ----------------------------------------------------
# ==========================================
# 4. OPTIONAL: AI WORKER (Adapters)
# ==========================================
# AI detection is completely decoupled and optional.
#
# -> IF YOU WANT CORE FEATURES ONLY (No AI):
# Leave this entire block commented out. No extra steps needed.
#
# -> IF YOU WANT AI DETECTION ENABLED:
# 1. Clone the AIAdapters codebase alongside this repository:
# git clone https://github.com/open-nvr/ai-adapter.git ../ai-adapter
# 2. Uncomment the full ai-adapters block below.
# 3. Run docker compose build again.
#
ai-adapters:
build:
context: ../ai-adapter
dockerfile: Dockerfile
container_name: opennvr_ai
restart: unless-stopped
# ----------------------------------------------------
# [LINUX] HOST MODE: Uncomment ONE line below
# network_mode: host
# ----------------------------------------------------
depends_on:
- opennvr-core
volumes:
- ../ai-adapter/model_weights:/app/model_weights
- shared_frames:/app/frames
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE:
networks:
- sentinel_internal
- public_uplink
# ----------------------------------------------------
# ==========================================
# NETWORKS
# ==========================================
# ----------------------------------------------------
# [WINDOWS/MAC] BRIDGE MODE: Uncomment lines below
networks:
sentinel_internal:
driver: bridge
public_uplink:
driver: bridge
# ----------------------------------------------------
# ==========================================
# VOLUMES
# ==========================================
volumes:
opennvr_db_data:
shared_frames: