tao
Caching dependency compilation in Docker build
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
Most Liked
NobbZ
Compile time configuration is the magic word.
1
tao
The first command to not use the cache is the first COPY:
remote: Sending build context to Docker daemon 162.3kB
remote:
remote:
remote: Step 1/26 : FROM elixir:1.9.0-alpine as build
remote: ---> 7a6d28e4b511
remote: Step 2/26 : RUN apk add --update git build-base
remote: ---> Using cache
remote: ---> 11da61788331
remote: Step 3/26 : RUN mkdir /app
remote: ---> Using cache
remote: ---> 2a0fd2bc9f5c
remote: Step 4/26 : WORKDIR /app
remote: ---> Using cache
remote: ---> 876adb368066
remote: Step 5/26 : RUN mix local.hex --force && mix local.rebar --force
remote: ---> Using cache
remote: ---> eb75832955a0
remote: Step 6/26 : ENV MIX_ENV=prod
remote: ---> Using cache
remote: ---> 3bc485b4dc82
remote: Step 7/26 : COPY mix.exs mix.lock ./
remote: ---> 223512ca1219
remote: Step 8/26 : COPY config config
remote: ---> 09c813490fe9
<snip>
I’m just separating it into two commands like you suggested now. I’ll update here when I try this out! FWIW this is running on Dokku, so caching should be supported.
1
Popular in Questions
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
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
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







