Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transmit Heroku environment variables to Docker instance

I build a RoR app on Heroku that must be run inside a Docker container. To do so I use the official Dockerfile. As it is very common with Heroku, I need a few add-ons to make this app fully operational. In production the variable DATABASE_URL is available within my app. But if I try some other add-ons that use environment variables (Mailtrap in my case), variables aren't copied into the instance during runtime.

So my question is simple: how can I make docker instances aware of the environment variables when executed on Heroku?

As you may ask, I already know that we can specified an environment directive right in docker-compose.yml. I would like to avoid that in order to be able to share this file through the project repository.

like image 537
Pirhoo Avatar asked Jan 15 '16 13:01

Pirhoo


2 Answers

I didn't find any documentation about it but t appears that Heroku change very recently the way it handles config vars in Docker containers: they are now replicated automatically (values from docker-compose.yml are simply ignored).

like image 128
Pirhoo Avatar answered Oct 23 '22 23:10

Pirhoo


The workaround to not commit sensitive config files, would be to create a docker-compose.yml**.example** with empty fields and commit it, then add docker-compose.yml to .gitignore.

Since that's not very practical on heroku, you can use the --env docker switch to add any variable to the container's environment.

Like this: docker run --env "MY_VAR=yolo" my_image:my_tag

You could also serve a private docker-config.yml from a secure site, that heroku would have access to (that would be my preferred solution in your case).

like image 28
Louis Kottmann Avatar answered Oct 24 '22 00:10

Louis Kottmann