Hello,
Fairly new to Docker, and I’m using docker compose to orchestrate services, both pre-built and custom - InfluxDB, Telegraf, Postgresql, NanoMQ, Backend and Frontend servers .
I’m using Docker Secrets to manage the usernames, passwords, etc.
I see that the secret can be from a file, or environment
secrets:
my_secret1:
file: ~/my_secret1.txt
my_secret2:
environment: MY_SECRET2
My question is around pros and cons of the two - i.e. file and environment.
Having a .env file with all the usernames, passwords, and tokens (that’s not checked into git) offers the advantage of easier management.
It looks like if I use the file option, I will need one file per secret , so that seems clunkier to manage.
One concern that people had was that the variables in the .env file would be accessible to all the containers, but that doesn’t seem to be true.
I checked with
docker compose exec influxdb2 /bin/printenv
docker compose exec telegraf /bin/printenv
etc, and each container only has the environment variables defined for it.
So far, I’ve not been able to find a definitive answer - just don’t use environment variables directly (which I don’t think I am). Secrets setting secrets from environment variables definitely seem to be a wrinkle that deserves greater understanding from a security perspective, so any information or pointers here would be greatly appreciated!
Thanks,
Sridhar
PS - Upon further searching, I read on Google AI results (so I don’t trust it until I see the source) that the .env file is used for variable subsitition and not passed directly to the containers, which would explain my above observations too. In that case, a well protected .env file that is not version controlled would seem the ideal way to keep all secretly safely in one place, and use that via secrets->environment ? Yes? No?