Skip to content
This repository was archived by the owner on Jun 13, 2026. It is now read-only.

Commit 6b21ffe

Browse files
committed
fix: correct docker-compose.dev.yml for concurrent testing
- Mount local config and data directories instead of named volumes - Use Alpine Linux with sqlite for lightweight reader container - Fix command syntax using proper YAML multiline format - Enable WAL mode for proper concurrent access - Mount data as read-only for reader container Now 'docker-compose -f docker-compose.dev.yml up' correctly demonstrates concurrent reading while the sensor is writing data.
1 parent 45843de commit 6b21ffe

1 file changed

Lines changed: 25 additions & 39 deletions

File tree

docker-compose.dev.yml

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
version: '3.8'
2-
3-
# Development configuration that works identically on Mac and Linux
4-
# Uses DELETE mode and named volumes for cross-platform compatibility
1+
# Development configuration for testing concurrent read/write
2+
# Tests sensor writing while readers access the database
53

64
services:
75
# Sensor simulator (writer)
@@ -10,50 +8,38 @@ services:
108
image: sensor-simulator:latest
119
container_name: sensor-writer
1210
environment:
13-
- LOG_LEVEL=INFO
14-
- MONITORING_ENABLED=true
15-
- MONITORING_PORT=8080
16-
# Don't set SENSOR_WAL - use DELETE mode for cross-platform compatibility
11+
- CONFIG_FILE=/config/config.yaml
12+
- IDENTITY_FILE=/config/node-identity.json
13+
- SENSOR_WAL=true # Use WAL mode for proper concurrent access
1714
volumes:
18-
- sensor-data:/app/data # Named volume works on all platforms
15+
- ./config:/config:ro # Mount local config directory
16+
- ./data:/app/data # Mount local data directory
1917
ports:
2018
- "8080:8080" # Monitoring API
21-
healthcheck:
22-
test: ["CMD", "curl", "-f", "http://localhost:8080/healthz"]
23-
interval: 30s
24-
timeout: 10s
25-
retries: 3
2619
restart: unless-stopped
2720

28-
# Your reader process (second container)
21+
# Reader process (monitoring container)
2922
reader:
30-
build: .
31-
image: sensor-simulator:latest
23+
image: alpine:latest
3224
container_name: sensor-reader
3325
depends_on:
3426
- sensor
3527
volumes:
36-
- sensor-data:/app/data:ro # Same volume, read-only
37-
command: |
38-
bash -c '
39-
echo "Waiting for database to be created..."
40-
while [ ! -f /app/data/sensor_data.db ]; do
41-
sleep 2
42-
done
43-
echo "Database found, starting reader..."
44-
while true; do
45-
echo "=== Reader Status at $$(date) ==="
46-
sqlite3 /app/data/sensor_data.db "
47-
SELECT '\''Total readings: '\'' || COUNT(*) FROM sensor_readings;
48-
SELECT '\''Latest: '\'' || MAX(timestamp) FROM sensor_readings;
49-
SELECT '\''Anomalies: '\'' || SUM(anomaly_flag) FROM sensor_readings;
50-
" 2>/dev/null || echo "Database temporarily locked, retrying..."
51-
sleep 10
52-
done
28+
- ./data:/data:ro # Mount data directory read-only
29+
command: >
30+
sh -c '
31+
apk add --no-cache sqlite &&
32+
echo "Waiting for database..." &&
33+
while [ ! -f /data/sensor_data.db ]; do sleep 2; done &&
34+
echo "Database found, starting monitoring..." &&
35+
while true; do
36+
echo "=== Reader Status at $$(date) ===" &&
37+
sqlite3 /data/sensor_data.db "
38+
SELECT \"Total readings: \" || COUNT(*) FROM sensor_readings;
39+
SELECT \"Latest: \" || MAX(timestamp) FROM sensor_readings;
40+
SELECT \"Anomalies: \" || SUM(anomaly_flag) FROM sensor_readings;
41+
" 2>/dev/null || echo "Database temporarily locked, retrying..." &&
42+
sleep 10;
43+
done
5344
'
5445
restart: unless-stopped
55-
56-
# Named volume for database (works on all platforms)
57-
volumes:
58-
sensor-data:
59-
driver: local

0 commit comments

Comments
 (0)