Best practices for managing environment variables in Symfony Docker projects #675
Replies: 2 comments 2 replies
-
I think it should mostly depend on how you manage your app across different environments (dev, stage, prod,...). |
Beta Was this translation helpful? Give feedback.
-
As said @bzoks , it's a better and easy to maintain approach keeping all your env vars inside .env.{your_environment} files, and only override APP_ENV or some other specific env vars directly in docker-compose.yaml. I also use the approach that in deploy time, override .env with correct env vars, depending on environment (we have local, test, stage and prod), and, in our pipeline scripts, we have an .env file for each environment and "inject" the corresponding .env file in env-file property in docker-compose, as @bzoks do as well. Take into account that is very recommended that you handle sensitive env vars like DB credentials or API Keys with a secret vault or something similar. |
Beta Was this translation helpful? Give feedback.
-
I'm currently working on a Symfony project that utilizes Docker, and I'm seeking clarification on the best practices for managing environment variables.
Symfony's documentation typically recommends using
.env
files for easier local configuration and variable overriding. Given this, is it still advisable to include all environment variables directly in thedocker-compose.yml
file, or should I primarily rely on.env
files?As a personal remark, I've noticed that new team members often default to adding new variables to the
.env
file, which leads to confusion when I explain that they should be defined in thedocker-compose.yml
instead.What are the advantages and disadvantages of each approach in a Dockerized Symfony application, and how can we maintain a clean and efficient configuration?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions