← Back to all fixes

Environment variable not available inside container

The Issue

You set `export DB_URL=postgres://...` on the host but `process.env.DB_URL` is undefined inside the container.

Root Cause

Host environment variables are not automatically passed into containers. You must explicitly pass them.

How to Fix
  1. Pass single vars: `docker run -e DB_URL=$DB_URL myapp`
  2. Pass a file: `docker run --env-file .env myapp`
  3. In Compose: use `environment:` or `env_file:` section under the service
  4. Verify inside the container: `docker exec <container> env | grep DB_URL`