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 Software Development To Help You Compete & Grow | Revelry and the Dockerfile it uses revelry_phoenix_app_template/Dockerfile at main · revelrylabs/revelry_phoenix_app_template · GitHub – 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
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
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 releaseand 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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








