Skip to content

Commit

Permalink
Reduce Docker image size from 165 MB to 32.8 MB (#131)
Browse files Browse the repository at this point in the history
Reduce Docker image size from 165 MB to 32.8 MB

Using multi-stage build available from Docker 17.05 to avoid having any
build artifacts.
  • Loading branch information
cbliard authored and edgurgel committed Aug 27, 2018
1 parent f3c27d2 commit 4c1c852
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
25 changes: 19 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
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

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/*/$APP_NAME.tar.gz

RUN mkdir /app && cp -r _build/prod/rel/$APP_NAME /app && rm -rf /source

FROM alpine:3.6

ENV APP_NAME poxa
ENV MIX_ENV prod

RUN apk --no-cache add bash openssl

COPY --from=builder /app /app

CMD /app/$APP_NAME/bin/$APP_NAME foreground
3 changes: 1 addition & 2 deletions rel/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,4 +30,3 @@ release :poxa do
]
plugin Conform.ReleasePlugin
end

0 comments on commit 4c1c852

Please sign in to comment.