Skip to content

16.3.3 .env variables are undefined in docker build #97959

Description

@VojtechVidra

Link to the code that reproduces this issue

https://github.com/VojtechVidra/next-16.3.3-env-docker-issue

To Reproduce

  1. Build the application with docker docker build . -t next-env-issue
  2. Run the built image docker run -p 3000:3000 next-env-issue
  3. Open the route file in browser http://localhost:3000/api/env

Current vs. Expected behavior

Current:

When I build with docker build and run it, the endpoint is returning null for both env variables.

Expected:

The variables are defined even when using docker build.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.6.0: Fri Jul 31 19:18:49 PDT 2026; root:xnu-12377.161.14~5/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 24.19.0
  npm: 11.17.0
  Yarn: N/A
  pnpm: 11.23.0
Relevant Packages:
  next: 16.3.3 // Latest available version is detected (16.3.3).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Runtime

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response

Metadata

Metadata

Assignees

Labels

RuntimeRelated to Node.js or Edge Runtime with Next.js.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions