Skip to content

Bug Report: Environment Variables Not Loaded in Docker Compose (Raw Mode) #2777

Description

@lefolalan

To Reproduce

  1. 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
  2. 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)
  3. Configure environment variables

    • Go to Environment tab
    • Add environment variables:
      APP_PORT=3000
      DB_HOST=postgres
      DB_PASSWORD=secret123
      
    • Save
  4. Deploy the application

    • Click Deploy button
    • Wait for deployment to complete
  5. 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."
      
  6. 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:

  1. When saving compose file in Raw tab:

    • composeFile is updated ✅
    • sourceType is set to "raw"
    • composePath is NOT updated - keeps old GitHub provider value (e.g., ./ or ./docker-compose.yml) ❌
  2. During deployment:

    • Compose file is created at: /etc/dokploy/compose/<app-name>/code/docker-compose.yml
    • .env file is created at: /etc/dokploy/compose/<app-name>/.env ❌ (WRONG - parent directory)
    • Docker Compose runs with cwd=/etc/dokploy/compose/<app-name>/code/
  3. Result:

    • Docker Compose looks for .env in /etc/dokploy/compose/<app-name>/code/.env
    • But .env is at /etc/dokploy/compose/<app-name>/.env
    • Environment variables are not found
    • Application starts with blank/default values ❌

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:

  1. When saving compose file in Raw tab:

    • composeFile is updated ✅
    • sourceType is set to "raw"
    • composePath is reset to "docker-compose.yml" ✅ (FIX NEEDED)
  2. During deployment:

    • Compose file is created at: /etc/dokploy/compose/<app-name>/code/docker-compose.yml
    • .env file is created at: /etc/dokploy/compose/<app-name>/code/.env ✅ (CORRECT)
    • Docker Compose runs with cwd=/etc/dokploy/compose/<app-name>/code/
  3. Result:

    • Docker Compose finds .env in the same directory ✅
    • Environment variables are loaded correctly
    • Application starts with correct values ✅

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 .env file 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions