Bug Report: Environment Variables Not Loaded in Docker Compose (Raw Mode)
To Reproduce
-
Create a compose application with GitHub provider
- Go to Projects → Create Compose Service
- Select GitHub as the source provider
- Configure repository, branch, and compose path (e.g.,
./) - Save the configuration
-
Switch to Raw mode
- Go to the compose service's General tab
- Click on the "Raw" tab
- Paste your docker-compose.yml content with environment variables:
services: backend: image: ghcr.io/example/app:latest environment: APP_PORT: ${APP_PORT} DB_HOST: ${DB_HOST} DB_PASSWORD: ${DB_PASSWORD} - Save the compose file (Click Save or press Ctrl+S)
-
Configure environment variables
- Go to Environment tab
- Add environment variables:
APP_PORT=3000 DB_HOST=postgres DB_PASSWORD=secret123 - Save
-
Deploy the application
- Click Deploy button
- Wait for deployment to complete
-
Check deployment logs
- You will see warnings like:
time="2025-10-05T17:11:18Z" level=warning msg="The \"APP_PORT\" variable is not set. Defaulting to a blank string." time="2025-10-05T17:11:18Z" level=warning msg="The \"DB_HOST\" variable is not set. Defaulting to a blank string." time="2025-10-05T17:11:18Z" level=warning msg="The \"DB_PASSWORD\" variable is not set. Defaulting to a blank string."
- You will see warnings like:
-
Verify the bug on the server
# Check where .env file is created (WRONG location) ls -la /etc/dokploy/compose/<app-name>/.env # Check where it SHOULD be (correct location - empty) ls -la /etc/dokploy/compose/<app-name>/code/.env # Check database composePath value docker exec -it $(docker ps -q -f name=dokploy-postgres) psql -U dokploy -d dokploy -c \ "SELECT \"composePath\", \"sourceType\" FROM compose WHERE \"appName\" = '<app-name>';"
Current vs. Expected behavior
What Happens:
-
When saving compose file in Raw tab:
composeFileis updated ✅sourceTypeis set to"raw"✅composePathis NOT updated - keeps old GitHub provider value (e.g.,./or./docker-compose.yml) ❌
-
During deployment:
- Compose file is created at:
/etc/dokploy/compose/<app-name>/code/docker-compose.yml✅ .envfile is created at:/etc/dokploy/compose/<app-name>/.env❌ (WRONG - parent directory)- Docker Compose runs with
cwd=/etc/dokploy/compose/<app-name>/code/✅
- Compose file is created at:
-
Result:
- Docker Compose looks for
.envin/etc/dokploy/compose/<app-name>/code/.env - But
.envis at/etc/dokploy/compose/<app-name>/.env - Environment variables are not found ❌
- Application starts with blank/default values ❌
- Docker Compose looks for
Database State:
-- After switching from GitHub to Raw
composePath = "./" -- ❌ Old GitHub value retained
sourceType = "raw" -- ✅ Correctly updated
File System State:
/etc/dokploy/compose/<app-name>/
├── .env # ❌ WRONG location (created here)
├── code/
│ ├── docker-compose.yml # ✅ Correct
│ └── .env # ❌ MISSING (should be here)
Deployment Logs:
Creating File 'docker-compose.yml' to /etc/dokploy/compose/<app-name>/code: ✅
File 'docker-compose.yml' created: ✅
╔══════════════════════════════════════════════════════════════════════════════╗
║ App Name: <app-name> ║
║ Build Compose 🐳 ║
║ Command: docker compose -p <app-name> -f docker-compose.yml up -d ║
║ Source Type: docker raw ✅ ║
╚══════════════════════════════════════════════════════════════════════════════╝
time="..." level=warning msg="The \"APP_PORT\" variable is not set. Defaulting to a blank string."
time="..." level=warning msg="The \"DB_HOST\" variable is not set. Defaulting to a blank string."
time="..." level=warning msg="The \"DB_PASSWORD\" variable is not set. Defaulting to a blank string."
Container <app-name>-backend-1 Started
Docker Compose Deployed: ✅
Expected Behavior
What Should Happen:
-
When saving compose file in Raw tab:
composeFileis updated ✅sourceTypeis set to"raw"✅composePathis reset to"docker-compose.yml"✅ (FIX NEEDED)
-
During deployment:
- Compose file is created at:
/etc/dokploy/compose/<app-name>/code/docker-compose.yml✅ .envfile is created at:/etc/dokploy/compose/<app-name>/code/.env✅ (CORRECT)- Docker Compose runs with
cwd=/etc/dokploy/compose/<app-name>/code/✅
- Compose file is created at:
-
Result:
- Docker Compose finds
.envin the same directory ✅ - Environment variables are loaded correctly ✅
- Application starts with correct values ✅
- Docker Compose finds
Database State (Expected):
-- After switching from GitHub to Raw
composePath = "docker-compose.yml" -- ✅ Reset to default
sourceType = "raw" -- ✅ Correctly updated
File System State (Expected):
/etc/dokploy/compose/<app-name>/
├── code/
│ ├── docker-compose.yml # ✅ Correct
│ └── .env # ✅ CORRECT location
Deployment Logs (Expected):
Creating File 'docker-compose.yml' to /etc/dokploy/compose/<app-name>/code: ✅
File 'docker-compose.yml' created: ✅
╔══════════════════════════════════════════════════════════════════════════════╗
║ App Name: <app-name> ║
║ Build Compose 🐳 ║
║ Command: docker compose -p <app-name> -f docker-compose.yml up -d ║
║ Source Type: docker raw ✅ ║
╚══════════════════════════════════════════════════════════════════════════════╝
Container <app-name>-backend-1 Starting
Container <app-name>-backend-1 Started
Docker Compose Deployed: ✅
No warnings - all environment variables loaded successfully!
Root Cause
The ComposeFileEditor component (apps/dokploy/components/dashboard/compose/general/compose-file-editor.tsx) only updates composeFile and sourceType when saving in Raw mode, but does not reset composePath.
File: apps/dokploy/components/dashboard/compose/general/compose-file-editor.tsx
Line: 74-78
await mutateAsync({
composeId,
composeFile: data.composeFile,
sourceType: "raw",
// ❌ Missing: composePath is not reset!
})
This causes composePath to retain its old value from the GitHub provider (e.g., ./), which then causes the .env file to be created in the wrong directory due to the dirname() logic in createEnvFile().
Impact
- Severity: High
- Affected Users: Anyone who switches from a Git provider (GitHub/GitLab/Bitbucket/Gitea) to Raw mode
- Workaround: Manually copy
.envfile to correct location after each deployment:cp /etc/dokploy/compose/<app-name>/.env /etc/dokploy/compose/<app-name>/code/.env docker compose -p <app-name> -f /etc/dokploy/compose/<app-name>/code/docker-compose.yml up -d --force-recreate
Provide environment information
- **OS:** Debian 12
- **Dokploy Version:** v0.25.4
- **VPS Provider:** OVH Cloud
- **Docker Compose Type:** docker-compose (not stack)
Which area(s) are affected? (Select all that apply)
Docker Compose
Are you deploying the applications where Dokploy is installed or on a remote server?
Same server where Dokploy is installed
Additional context
No response
Will you send a PR to fix it?
Maybe, need help
This bug still persists, was there a regression?