CodePark/ questions / Environment, config & secrets
START PRACTICINGPRACTICE
Backend question · Docker › Environment, config & secrets

The image has ENV LOG_LEVEL=info. The service has env_file: app.env containing LOG_LEVEL=debug, and environment: { LOG_LEVEL: warn }. What does the container see after docker compose up?

warn

The container sees warn. In Compose, environment wins over env_file. Both of them override the image's ENV.

The order from strongest to weakest is:

•
docker compose run -e (this beats all the others)
•
environment
•
env_file
• the image's
ENV

"The container fails because the variable is defined twice" is wrong. Defining a variable in several places is normal, and Compose simply picks the stronger one.