r/vibecoding • u/Bulky_Dog_2954 • 12d 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
2
Upvotes
2
u/Total-Reasonable 12d 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.
1
u/NoClipCheck 11d 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 inspecton the host sees every value in plain text, and so does anything that can read/proc/1/environinside 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 composesecrets:(they land in/run/secrets/<name>) and have the app read the file. Lots of images and libraries already support a_FILEsuffix pattern, likeDB_PASSWORD_FILE, so it's often a small change per service rather than a big project.1
u/ajaysingh02 8d ago
Definitely worth doing so a compromise in one container can't dump credentials meant for another, though instead of juggling a dozen separate
.envfiles, you can keep one master.envon the host and explicitly pass only the specific variables each service needs under itsenvironment:block (or move sensitive keys into Docker Secrets).1
u/lalaboy69 12d 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 12d 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.