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
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Hi,
I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
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
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
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
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function:
-dialyzer...
New
Other popular topics
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help.
Where are they similar?
Where do they differ the m...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
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
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
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








