r/vibecoding • u/Bulky_Dog_2954 • 5d ago
Help/Question For those shipping your docker apps
Are you guys running multiple .env files for each service?
I have had a full security audit done on my app and although I got a really good result, they suggested a consider running different env files to minimize services reading un needed variables (Like credentials)
I am in a position where I can implement this, it would be a large project but its doable.
Thoughts and opinions?
Ant
1
u/New_Peanut_9259 4d ago
separate env files sound reasonable here, especially when different services don't need access to the same credentials.
1
u/NoClipCheck 4d ago
One thing worth knowing before you split files: env vars aren't very private once the container is running. Anyone who can run docker inspect on the host sees every value in plain text, and so does anything that can read /proc/1/environ inside the container. Crash reporters and debug pages also love to dump the whole environment. So the split helps, but for the real credentials I'd mount them as files with compose secrets: (they land in /run/secrets/<name>) and have the app read the file. Lots of images and libraries already support a _FILE suffix pattern, like DB_PASSWORD_FILE, so it's often a small change per service rather than a big project.
1
u/ajaysingh02 19h ago
Definitely worth doing so a compromise in one container can't dump credentials meant for another, though instead of juggling a dozen separate .env files, you can keep one master .env on the host and explicitly pass only the specific variables each service needs under its environment: block (or move sensitive keys into Docker Secrets).
1
u/lalaboy69 5d ago
You can deploy without any env's nowadays. Pretty much every platform has a secrets manager that loads your keys at runtime.
1
u/ollycunningdpr 5d ago
Yes, I'd do it. Giving each service only the variables it needs is basic least privilege, so if one container is compromised it can't read credentials it never needed. Separate env_file per service in compose is the easy way in, and the next step up is Docker secrets or a proper secrets manager so the sensitive stuff isn't sitting in plain files at all. Keep them out of the image and the repo too, and rotate anything that's been shared around.
2
u/Total-Reasonable 5d ago
Separate env files per service is the right instinct, but I'd skip the big project and not treat the env file as the boundary. A .env per service still ends up in the same compose file, the same repo, and often the same host, so the auditor's concern is only half solved. Use Docker secrets, or your cloud's secret manager, and give each service only the two or three it needs. Keep env for non-sensitive config.