4.2.8.2 ENV Runtime Defaults
A focused guide to ENV Runtime Defaults, connecting core concepts with practical Docker and container operations.
ENV runtime defaults are environment variables set in a Dockerfile specifically to configure how the containerized application behaves once running, providing sensible out-of-the-box values that can still be adjusted per environment without rebuilding the image.
Setting Sensible Application Defaults
Runtime defaults typically cover configuration the application reads directly — log verbosity, default ports, feature flags — chosen to work reasonably well without requiring every deployment to explicitly override them.
ENV LOG_LEVEL=info
ENV PORT=8080
ENV ENABLE_METRICS=true
A container started from this image behaves sensibly by default, without needing any of these explicitly set at run time.
Overriding Runtime Defaults Per Environment
The same defaults can be selectively overridden to suit a specific deployment environment's needs, without touching the image itself.
docker run -e LOG_LEVEL=debug -e PORT=9090 myapp:1.0
Documenting Runtime Defaults Through Their Presence
Because ENV instructions are visible directly in the Dockerfile, they double as documentation of which environment variables the application is aware of and what reasonable values look like, which is useful information for anyone deploying the image without needing to read the application's source code.
ENV DATABASE_URL=postgres://localhost:5432/app
Even though this default would rarely be correct in an actual deployment, its presence reveals that the application expects a DATABASE_URL variable and shows the expected format.
Avoiding Defaults That Are Actually Required to Change
For values that must always be explicitly supplied (such as secrets or connection strings unique to each deployment), setting a clearly invalid or placeholder default can help surface a missing configuration value quickly, rather than silently running with an unsuitable default.
ENV DATABASE_URL=""
An empty default like this is likely to cause an obvious failure if the application attempts to use it without the value being explicitly supplied, surfacing the missing configuration immediately.
Why Runtime Defaults Matter
Thoughtfully chosen runtime defaults make an image more convenient to use out of the box, while clear, obviously-placeholder defaults for genuinely required values help prevent a deployment from silently running with incorrect or missing configuration.