lumenwrites
lumenwrites

Reputation: 1507

Dockerfile - how do I pass passwords from a file into ENV variables?

I want to store all the confidential environment variables - POSTGRES_PASSWORD, SECRET_KEY, etc, in a separate file, so that they don't get committed to github.

How can I include these variables into the Dockerfile, so that I could use them to run migrations and stuff like that?

Upvotes: 0

Views: 522

Answers (2)

Jayaram
Jayaram

Reputation: 6606

If you are running each container through your CLI .. you should pass your variables as an argument as a string in the format -e "foo=bar".

The better way i can suggest is if you're using something like docker-compose (which i recommend) for deployment. you can set all your passwords in a .env file and reference them in your docker-compose file.

web:
    container_name: web
    env_file: .env

Upvotes: 2

quetzaluz
quetzaluz

Reputation: 1131

If you're using Chef, The best and expected practice is to use Chef Data bags -- see https://docs.chef.io/data_bags.html

Databags allow you to commit these keys to your repo in an encrypted form; upon deployment, they are decrypted and usable for your environment files.

Besides using chef, the option mentioned by the poster using compose and converge is your best bet.

Upvotes: 0

Related Questions