-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
117 lines (111 loc) · 3.02 KB
/
docker-compose.yml
File metadata and controls
117 lines (111 loc) · 3.02 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
services:
# PostgreSQL Database
postgres:
image: postgres:15-alpine
container_name: iot-postgres
restart: unless-stopped
environment:
POSTGRES_USER: iot_user
POSTGRES_PASSWORD: iot_password
POSTGRES_DB: sensor_db
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5433:5432" # External:Internal - Changed to avoid conflict
networks:
- iot-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U iot_user -d sensor_db"]
interval: 10s
timeout: 5s
retries: 5
# Mosquitto MQTT Broker
mosquitto:
image: eclipse-mosquitto:2.0
container_name: iot-mosquitto
restart: unless-stopped
volumes:
- ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
- mosquitto_data:/mosquitto/data
- mosquitto_logs:/mosquitto/log
ports:
- "1884:1883" # External:Internal - Changed to avoid conflict
- "9001:9001" # WebSocket (optional)
networks:
- iot-network
healthcheck:
test: ["CMD-SHELL", "mosquitto_sub -t '$$SYS/#' -C 1 -i healthcheck"]
interval: 30s
timeout: 10s
retries: 3
# FastAPI Application
fastapi-app:
build:
context: ./fastapi-app
dockerfile: Dockerfile
container_name: iot-fastapi
restart: unless-stopped
environment:
POSTGRESQL_HOST: postgres
POSTGRESQL_PORT: 5432 # Internal port (inside Docker network)
POSTGRESQL_USER: iot_user
POSTGRESQL_PASSWORD: iot_password
POSTGRESQL_DBNAME: sensor_db
POSTGRESQL_URI: postgresql://iot_user:iot_password@postgres:5432/sensor_db
MQTT_BROKER: mosquitto
MQTT_PORT: 1883 # Internal port (inside Docker network)
ports:
- "8000:8000"
depends_on:
postgres:
condition: service_healthy
mosquitto:
condition: service_started
networks:
- iot-network
volumes:
- ./fastapi-app:/app # For development hot-reload
# Prometheus (Optional - for monitoring)
prometheus:
image: prom/prometheus:latest
container_name: iot-prometheus
restart: unless-stopped
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- "9090:9090"
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
networks:
- iot-network
depends_on:
- fastapi-app
# Grafana (Optional - for visualization)
grafana:
image: grafana/grafana:latest
container_name: iot-grafana
restart: unless-stopped
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: admin
GF_INSTALL_PLUGINS: grafana-clock-panel
volumes:
- grafana_data:/var/lib/grafana
ports:
- "3000:3000"
networks:
- iot-network
depends_on:
- prometheus
networks:
iot-network:
driver: bridge
volumes:
postgres_data:
mosquitto_data:
mosquitto_logs:
prometheus_data:
grafana_data: