fireproofsocks

fireproofsocks

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…

Showing Posts 1 to 6

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I have totally different dockerfiles for prod vs test because they have different dependencies. As such I can just hard code the env at the top.

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
fireproofsocks

fireproofsocks OP

Interesting… I’m surprised a bit by how many people I’ve heard from who use different Dockerfiles for prod as they do for test runs. Are people worried about them specifying different dependencies or compiling different libraries? I can think of a few times where this type of thing bit us, e.g.

  • Some low-level SSL encryption stuff was compiled in one environment, but not in another. All requests to https API endpoints barfed.
  • Some developers wrapped bits of code in conditionals that tested for environment

Having a single Dockerfile for both prod and test would alleviate one of those problems… I guess I would prefer my test runs to test things in a way that mimics prod as closely as possible, and I always felt that a separate Dockerfile could potentially cause problems in that regard…

NobbZ

NobbZ

Well, usually you build the release using the docker file which you run through the resulting images entry point, there is no room for running tests in this scenario, as you can’t run the tests from the release.

To run the tests I have a generic elixir image that just runs the tests.

Also for the latter I usually do not care if the image is perhaps 50 or 100 mb more in its size. The testrunners will probably cache it for a long time anyway.

The image under deploy though also gets regular updates of the base image, it gets probably redownload on deploy without any cached layers beeing reusable, also to be able to roll back we have a policy to keep at least the last 10 to 20 versions or sometimes even of the last year or more (depends on customer). So here every byte of the final image matters.

This is why we use different images. Because they serve different purposes under different environments.

We do not use elixir in my company though, but the flow is the same across about all languages used by us and our customers.

Also I have to say, dockerfiles for test usually get handwaved in the review, such that testing is up and running quickly again, but those for production require review by certain people for security audits and to make sure they are in size boundaries, not keeping unnecessary libraries etc…

LostKobrakai

LostKobrakai

This is quite often the case for compiled languages, where in production you’ll be running of a minimal runtime, while in development you need a full blown sdk for doing things the runtime never needs.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews