- Add docker-compose.sh wrapper script that auto-detects host IP - Update docker-compose.yml to use environment variable substitution - Update Supabase config.toml files to use HOST_SITE_URL and SUPABASE_API_URL env vars - Add scripts/get-host-ip.sh for IP detection - Add scripts/set-host-env.sh for environment setup - Add scripts/supabase-with-env.sh wrapper for Supabase CLI - Add documentation for Docker Compose environment setup - Update README.md with new usage instructions - Replace hardcoded URLs with dynamic environment variables
4.3 KiB
Docker Compose Environment Setup
Overview
Docker Compose now automatically detects the host machine's IP address and sets all necessary environment variables. No manual script execution is required!
Quick Start
Instead of running docker compose directly, use the wrapper script:
./docker-compose.sh up -d
./docker-compose.sh down
./docker-compose.sh logs -f
# etc.
The wrapper script automatically:
- Detects your host machine's IP address
- Sets
HOST_SITE_URLfor Supabase auth redirects - Sets all
VITE_*environment variables for React apps - Generates/updates the
.envfile - Runs docker-compose with all your arguments
What Gets Auto-Configured
The script automatically sets these environment variables:
HOST_IP- The detected host machine IP (e.g.,192.168.1.87)HOST_SITE_URL- Full URL for Supabase auth (e.g.,http://192.168.1.87:3000)VITE_SUPABASE_URL- Supabase API URL (e.g.,http://192.168.1.87:54321)VITE_MEDIA_API_URL- Media API URL (e.g.,http://192.168.1.87:8090)VITE_VISION_API_URL- Vision API URL (e.g.,http://192.168.1.87:8000)
Manual Override
If you need to override the auto-detected values, you can:
-
Set environment variables before running:
export HOST_IP=192.168.1.100 ./docker-compose.sh up -d -
Edit the
.envfile (generated by the script):# Edit .env file nano .env # Then run docker compose normally docker compose up -d -
Use docker-compose directly (with fallback values):
# The docker-compose.yml has fallback values, so this still works docker compose up -d
Environment Files
Root .env File
The root .env file is auto-generated by docker-compose.sh and contains:
HOST_IP=192.168.1.87
HOST_SITE_URL=http://192.168.1.87:3000
VITE_SUPABASE_URL=http://192.168.1.87:54321
VITE_MEDIA_API_URL=http://192.168.1.87:8090
VITE_VISION_API_URL=http://192.168.1.87:8000
This file is automatically updated each time you run docker-compose.sh.
management-dashboard-web-app/.env
This file is optional and can contain:
VITE_SUPABASE_URL- Overrides the docker-compose valueVITE_SUPABASE_ANON_KEY- Required for Supabase authentication
Example:
VITE_SUPABASE_URL=http://localhost:54321
VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
For Supabase CLI
When using Supabase CLI (not Docker Compose services), you still need to set HOST_SITE_URL:
# Option 1: Use the environment setup script
source ./scripts/set-host-env.sh
supabase start
# Option 2: Use the wrapper script
./scripts/supabase-with-env.sh start
# Option 3: Manual
export HOST_SITE_URL="http://$(./scripts/get-host-ip.sh):3000"
supabase start
How It Works
- IP Detection:
scripts/get-host-ip.shdetects the host IP using multiple methods - Variable Setting:
docker-compose.shsets all environment variables - Env File Generation: Creates/updates
.envfile for docker-compose to read - Docker Compose: Reads
.envand substitutes${VARIABLE}syntax indocker-compose.yml
Troubleshooting
IP Detection Fails
If the script can't detect your IP:
# Check what IP is detected
./scripts/get-host-ip.sh
# Manually set it
export HOST_IP=192.168.1.100
./docker-compose.sh up -d
Services Can't Connect
Make sure:
- The detected IP is accessible from your network
- Firewall allows connections on the required ports
- Services are using the correct URLs (check container logs)
Using Different Ports
If your services run on different ports, edit .env after it's generated:
./docker-compose.sh config # Generates .env
nano .env # Edit ports
docker compose up -d # Use docker compose directly now
Migration from Manual Setup
If you were previously setting environment variables manually:
- Remove manual exports from your shell profile
- Use
./docker-compose.shinstead ofdocker compose - Delete old
.envfiles if they have hardcoded values (the script will regenerate)
Example Workflow
# 1. Start all services (auto-detects IP)
./docker-compose.sh up -d
# 2. Check logs
./docker-compose.sh logs -f web
# 3. Stop services
./docker-compose.sh down
# 4. Restart with new IP detection
./docker-compose.sh up -d
That's it! No more manual environment variable setup needed.