0

My goal is to use environment variables in the docker-compose.yml file that can be referenced inside the application itself like in config/database.yml

docker-compose.yml

 ... environment: $DB_NAME: myapplication $DB_USER: appadmin $DB_PASS: secret ... 

config/database.yml

... database: $DB_NAME db_user: $DB_USER db:pass: $DB_PASS ... 

But no matter how do I try to send the variables to my file, They don't get recognised. :(

1
  • Does the application parsing config/database.yml inside the container expand environment variables defined in that file? Commented Jan 28, 2020 at 20:06

1 Answer 1

0

You're just trying to set the variables in the compose file? You shouldn't need the "$" in front of them in that case:

environment: - DB_NAME=database - DB_USER=appadmin - DB_PASS=secret 

You could use mappings too:

environment: DB_NAME: database DB_USER: appadmin DB_PASS: secret 

When you reference them in the database config file, you can just use the variable name too, again, without the "$":

environment: DB_NAME DB_USER DB_PASS 

You can check the Compose Environment Options documentation and the Compose Environment reference for further information.

Hope that helps.

1
  • I'm trying to set the variable values in the compose file, but then trying to call them inside the docker images database config file. Gonna try soon the non-$ type of calling it, but honestly, I don't know if that could work. I mean isn't the whole point of $ to let the system know that is a variable and not a string? Commented Feb 3, 2020 at 12:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.