Skip to content

Commit 56e602b

Browse files
author
Keoma Wright
committed
fix: resolve .env.local not loading in docker compose
Fixes issue #1827 where Docker Compose wasn't properly loading .env.local file. Problem: - Docker Compose expects .env file for variable substitution but docs say to use .env.local - This caused environment variables to not be loaded in Docker containers Solution: - Updated docker-compose.yaml to load both .env and .env.local files - Created setup-env.sh script to help users sync .env.local to .env - Updated documentation with clear instructions for Docker users - Maintains backward compatibility with existing setups Changes: - Modified docker-compose.yaml to use array syntax for env_file - Added scripts/setup-env.sh helper script - Updated CONTRIBUTING.md and index.md documentation This ensures environment variables work correctly in Docker while maintaining the security best practice of using .env.local for sensitive data. Contributed by: Keoma Wright
1 parent bab9a64 commit 56e602b

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

docker-compose.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ services:
77
target: bolt-ai-production
88
ports:
99
- '5173:5173'
10-
env_file: '.env.local'
10+
env_file:
11+
- '.env'
12+
- '.env.local'
1113
environment:
1214
- NODE_ENV=production
1315
- COMPOSE_PROFILES=production
@@ -37,7 +39,9 @@ services:
3739
image: bolt-ai:development
3840
build:
3941
target: bolt-ai-development
40-
env_file: '.env.local'
42+
env_file:
43+
- '.env'
44+
- '.env.local'
4145
environment:
4246
- NODE_ENV=development
4347
- VITE_HMR_PROTOCOL=ws

docs/docs/CONTRIBUTING.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,20 @@ Interested in maintaining and growing the project? Fill out our [Contributor App
9595
OPENAI_API_KEY=XXX
9696
...
9797
```
98-
3. Optionally set:
98+
3. **For Docker users**: Run the setup script or manually copy `.env.local` to `.env`:
99+
```bash
100+
# Option 1: Use the setup script
101+
./scripts/setup-env.sh
102+
103+
# Option 2: Manual copy
104+
cp .env.local .env
105+
```
106+
Docker Compose requires `.env` for variable substitution.
107+
4. Optionally set:
99108
- Debug level: `VITE_LOG_LEVEL=debug`
100109
- Context size: `DEFAULT_NUM_CTX=32768`
101110

102-
**Note**: Never commit your `.env.local` file to version control. It’s already in `.gitignore`.
111+
**Note**: Never commit your `.env.local` or `.env` files to version control. They're already in `.gitignore`.
103112
104113
### 2️⃣ Run Development Server
105114

docs/docs/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ ANTHROPIC_API_KEY=XXX
9999

100100
Once you've set your keys, you can proceed with running the app. You will set these keys up during the initial setup, and you can revisit and update them later after the app is running.
101101
102-
**Note**: Never commit your `.env.local` file to version control. It’s already included in the `.gitignore`.
102+
**Important for Docker users**: Docker Compose needs a `.env` file for variable substitution. After creating `.env.local`:
103+
- Run `./scripts/setup-env.sh` to automatically sync the files, or
104+
- Manually copy: `cp .env.local .env`
105+
106+
**Note**: Never commit your `.env.local` or `.env` files to version control. They're already included in the `.gitignore`.
103107

104108
#### 2. Configure API Keys Directly in the Application
105109

scripts/setup-env.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Setup script for Docker environment variables
4+
# This script helps resolve the issue where .env.local is not being loaded in Docker
5+
6+
echo "🔧 Setting up environment files for Docker..."
7+
8+
# Check if .env.local exists
9+
if [ -f ".env.local" ]; then
10+
echo "✅ Found .env.local file"
11+
12+
# Create symlink or copy to .env for Docker Compose
13+
if [ ! -f ".env" ] || [ ".env" -ot ".env.local" ]; then
14+
echo "📋 Copying .env.local to .env for Docker Compose compatibility..."
15+
cp .env.local .env
16+
echo "✅ Environment file synced"
17+
else
18+
echo "ℹ️ .env file already up to date"
19+
fi
20+
else
21+
echo "⚠️ No .env.local file found"
22+
23+
# Check if .env.example exists and offer to copy it
24+
if [ -f ".env.example" ]; then
25+
echo "📋 Found .env.example file"
26+
read -p "Would you like to create .env.local from .env.example? (y/n) " -n 1 -r
27+
echo
28+
if [[ $REPLY =~ ^[Yy]$ ]]; then
29+
cp .env.example .env.local
30+
cp .env.example .env
31+
echo "✅ Created .env.local and .env from .env.example"
32+
echo "📝 Please edit .env.local with your API keys"
33+
fi
34+
fi
35+
fi
36+
37+
echo "✨ Environment setup complete!"
38+
echo ""
39+
echo "📚 Note: Docker Compose reads both .env and .env.local files"
40+
echo " - .env is used for variable substitution in docker-compose.yaml"
41+
echo " - .env.local is passed to the container for runtime variables"

0 commit comments

Comments
 (0)