Skip to content

Docker dev server doesn't receive environment variables from .env files #881

@acreeger

Description

@acreeger

Problem

When using Docker-based dev servers (devServer: 'docker'), environment variables from .env files are not passed into the container. This means any dev server that depends on environment variables (e.g., DATABASE_URL, API_KEY) will fail to start or behave correctly in Docker mode.

Root Cause

There are two related gaps:

1. il open / il run never load .env files

ensureServerRunning() in DevServerManager doesn't accept or pass envOverrides. Neither open.ts nor run.ts call loadWorkspaceEnv() — they only use getWorkspacePort() for port calculation.

  • In native mode, this accidentally works because the child process inherits process.env from the host shell (which may include sourced .env vars)
  • In Docker mode, this completely fails — containers are isolated and only receive explicitly passed -e flags

2. Docker strategy has no .env file mechanism

startDockerServer() calls runContainerDetached() without any envOverrides. The container only receives PORT. There is no --env-file flag or .env volume mount.

What works today

il dev-server <issue> (foreground mode) correctly loads .env files via loadWorkspaceEnv() and passes them as envOverrides — this works in both native and Docker modes.

Suggested fix

  1. Add envOverrides parameter to DevServerManager.ensureServerRunning() and plumb it through to startDockerServer()runContainerDetached()
  2. Have open.ts and run.ts call loadWorkspaceEnv() (when sourceEnvOnStart is enabled) and pass the result through
  3. Consider also supporting Docker's --env-file flag as an alternative/complement to individual -e flags

Affected code paths

  • src/lib/DevServerManager.tsensureServerRunning(), startDockerServer()
  • src/lib/DockerDevServerStrategy.tsrunContainerDetached()
  • src/commands/open.tsensureServerRunning() call
  • src/commands/run.tsensureServerRunning() call
  • src/utils/env.tsloadWorkspaceEnv()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions