New mix releases environment variables at runtime

Hi all! I haven’t worked with Elixir since v1.7. I was just checking out the new mix release functionality and I was thinking about how I used to work with environment variables before.

Is there a way with the new mix release process to read environment variables at runtime? Or do they still have to be populated when compiling the release? For example, I want to compile a release tarball, then send it to my remote server, then run it with a specific port specified at runtime with an environment variable.


config/releases.exs is evaluated on startup of the release.


See documentation in Config.

1 Like

@LostKobrakai @hauleth Thanks! I don’t see anything in that documentation about using environment variables, but I do see the config providers structure.

Would you recommend that I basically just implement a simple config provider which reads from environment variables using System.fetch_env(varname) to do so?

According to this part of the docs the config/releases.exs will be evaluated on each start of the release, which mean you can use System.fetch_env/1 there and it will work as expected.


If you are looking for a tutorial style application that leverages Mix releases, I put something together on my blog using Docker:

Step 2 is where I go over using a release.ex file. Hopefully that helps guide you in the right direction.


Oh great that is awesome! It didn’t used to work that way did it?

Wow that is awesome! Definitely saving this article. I use Docker to setup automatic deployments on my CI so this is going to be perfect. I have an old app setup using Distillery but I’ve been excited to get back into it and set it up with the new Mix release method.

1 Like

Earlier there was no built in releases, so no.