fireproofsocks

fireproofsocks

Should MIX_ENV be supplied as a Docker build-arg?

I’m working on dockerizing a Phoenix app and I’m wondering if the MIX_ENV needs to be set as a Docker build-arg. Because environment variables are read at compile time, I think your Docker image would have to know about which MIX_ENV it should be using, right? In other words, when you build a Dockerfile for an Elixir/Phoenix app, you are building an environment-specific image (e.g. the prod build, the test build, etc).

I’m looking over this blog post https://revelry.co/elixir-releases/ and the Dockerfile it uses https://github.com/revelrylabs/revelry_phoenix_app_template/blob/master/Dockerfile – hard-codes the MIX_ENV right at the top of the file, but it seems to me that this could be replaced by a build-arg.

How are others handling this? A lot of CI could be simplified if you could build once and choose the environment later…

Most Liked

riebeekn

riebeekn

If you don’t have different dependencies, and you just need different environment specific settings you can just use fetch_env in your releases.exs file.

This is a really good tutorial I found useful: https://akoutmos.com/post/multipart-docker-and-elixir-1.9-releases/

And a shameless plug, I wrote a post (largely based on the above) for creating a release / docker image for use in a GitLab pipeline: https://experimentingwithcode.com/setting-up-a-phoenix-ci-cd-pipeline-on-gitlab-part-2/

stefanchrobot

stefanchrobot

We hardcode MIX_ENV in our Dockerfiles since prod and test builds are different:

  • the prod image is a multi-stage build and uses mix release and minimal set of permissions to run the app
  • the test image tries to mimic the prod image, but just compiles the app and adds write permissions required by mix test

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement