tao

tao

I’m deploying a Phoenix app with Elixir releases and Docker. The Phoenix docs have an example dockerfile you can use – mine is based on that one.

I’ve set up the file so that dependency downloads and compilation should be cached by Docker, but this isn’t happening. This is slowing down deploys a bit. Can anyone spot why Docker isn’t caching dependencies? Even when mix.exs is unchanged, it redownloads and rebuilds them.

FROM elixir:1.9.0-alpine as build

# install build dependencies
RUN apk add --update git build-base

# prepare build dir
RUN mkdir /app
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
  mix local.rebar --force

# set build ENV
ENV MIX_ENV=prod

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get
RUN mix deps.compile
COPY config config

# build assets
# COPY assets assets
# RUN cd assets && npm install && npm run deploy
# RUN mix phx.digest

# build project
COPY priv priv
COPY lib lib
RUN mix compile

# build release
COPY rel rel
RUN mix release

Showing Posts 1 to 10

NobbZ

NobbZ

Do you touch the mix.lock or mix.exs between builds?

From a theoretical point of view, your file should work.

tao

tao OP

Interesting. Nope, the dependencies get redownloaded and rebuilt even when I haven’t touched those files – that’s why I’m confused and why I opened this thread!

The Phoenix docs actually have a slightly different order:

COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get
RUN mix deps.compile

I moved this around since I didn’t want to redownload deps after changing configuration, but now I’m starting to wonder if there’s a reason to their ordering?

NobbZ

NobbZ

Oh, yes. Config needs to be available, as it might affect how dependencies are built.

cnck1387

cnck1387

Can you give an example where a config’s value would determine how dependencies are built?

I know you can choose to install packages based on the environment with mix but isn’t that controlled by the mix command itself with --only prod along with mix.exs?

NobbZ

NobbZ

Compile time configuration is the magic word.

tao

tao OP

Okay, I’ll try going back to the original config from the docs!

I’m not sure I understand how this could make Docker not cache things, though. All that Docker knows is that nothing has changed in mix.exs and mix.lock, yet it still re-runs the dependency steps instead of using the cached versions.

NobbZ

NobbZ

Yeah, I do not understand that as well… Weird.

jola

jola

As an example, Logger lets you remove log calls from modules at compile time, even in dependencies, through the config option :compile_time_purge_matching.

cnck1387

cnck1387

Thanks, but would this change which dependencies get mix installed?

jola

jola

Oh, sorry, I was just respond to your comment “determine how dependencies are built” and giving an example of the compile time configuration @NobbZ mentioned. Not sure how config would affect which dependencies get installed though, since that’s the job of the mix.exs and mix.lock.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
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
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
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews