From be4cdafa6a67b58f3ad32df51edcdbb146ae3da6 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Thu, 23 Aug 2018 14:32:10 +0200 Subject: [PATCH 1/3] Reduce Docker image size from 165 MB to 115 MB Using multi-stage build available from Docker 17.05 to avoid having any build artifacts. --- Dockerfile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f43de3..2df26ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -FROM elixir:1.5.2-alpine +FROM elixir:1.5.2-alpine AS builder ENV APP_NAME poxa ENV MIX_ENV prod -RUN apk --update add bash git erlang-xmerl erlang-crypto erlang-sasl && rm -rf /var/cache/apk/* +RUN apk --no-cache add git erlang-xmerl erlang-crypto erlang-sasl COPY . /source WORKDIR /source @@ -14,6 +14,14 @@ RUN mix compile RUN echo "" > config/poxa.prod.conf RUN mix release -RUN mkdir /app && cp -r _build/prod/rel/$APP_NAME /app && rm -rf /source + +FROM elixir:1.5.2-alpine + +ENV APP_NAME poxa +ENV MIX_ENV prod + +RUN apk --no-cache add bash erlang-xmerl erlang-crypto erlang-sasl + +COPY --from=builder /source/_build/prod/rel /app CMD /app/$APP_NAME/bin/$APP_NAME foreground From 61d56b912d5f4ada5010d39483ababc6bedef91d Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Thu, 23 Aug 2018 16:52:11 +0200 Subject: [PATCH 2/3] More aggressive reduction of docker image size From 114 to 32 MB --- Dockerfile | 9 ++++++--- rel/config.exs | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2df26ea..bbd521d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,15 +13,18 @@ RUN mix deps.get RUN mix compile RUN echo "" > config/poxa.prod.conf RUN mix release +RUN mkdir -p /app/$APP_NAME +WORKDIR /app/$APP_NAME +RUN tar xzf /source/_build/prod/rel/$APP_NAME/releases/0.7.1/$APP_NAME.tar.gz -FROM elixir:1.5.2-alpine +FROM alpine:3.6 ENV APP_NAME poxa ENV MIX_ENV prod -RUN apk --no-cache add bash erlang-xmerl erlang-crypto erlang-sasl +RUN apk --no-cache add bash openssl -COPY --from=builder /source/_build/prod/rel /app +COPY --from=builder /app /app CMD /app/$APP_NAME/bin/$APP_NAME foreground diff --git a/rel/config.exs b/rel/config.exs index 4de4e9e..86ad8bc 100644 --- a/rel/config.exs +++ b/rel/config.exs @@ -18,7 +18,7 @@ environment :dev do end environment :prod do - set include_erts: false + set include_erts: true set include_src: false set cookie: :"xR=}b(ZcHU8M1Lu&642.m{u{O)H]WD>[&&_5t8FW3t5mxy4nw=de~;lEbw*?EFXC" end @@ -30,4 +30,3 @@ release :poxa do ] plugin Conform.ReleasePlugin end - From 9133535000f0a7598414b189bff9026bb4465433 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Mon, 27 Aug 2018 10:38:12 +0200 Subject: [PATCH 3/3] Remove hardcoded version --- Dockerfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index bbd521d..745d61b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,14 +8,16 @@ RUN apk --no-cache add git erlang-xmerl erlang-crypto erlang-sasl COPY . /source WORKDIR /source -RUN mix local.hex --force && mix local.rebar --force -RUN mix deps.get -RUN mix compile +RUN mix do \ + local.hex --force, \ + local.rebar --force, \ + deps.get, \ + compile RUN echo "" > config/poxa.prod.conf RUN mix release RUN mkdir -p /app/$APP_NAME WORKDIR /app/$APP_NAME -RUN tar xzf /source/_build/prod/rel/$APP_NAME/releases/0.7.1/$APP_NAME.tar.gz +RUN tar xzf /source/_build/prod/rel/$APP_NAME/releases/*/$APP_NAME.tar.gz FROM alpine:3.6