Skip to content

Instantly share code, notes, and snippets.

@andrius
Last active January 2, 2023 13:39
Show Gist options
  • Save andrius/e48b57c0cd45e195a752d9d5ddf0b336 to your computer and use it in GitHub Desktop.
Save andrius/e48b57c0cd45e195a752d9d5ddf0b336 to your computer and use it in GitHub Desktop.
multi-stage Elixir build (this create production-ready image, small as possible) #docker #elixir
#===========
#Build Stage
#===========
FROM elixir:alpine as build
#Copy the source folder into the Docker image
COPY elixir-docker-guide/ .
#Install dependencies and build Release
ENV MIX_ENV prod
RUN mix local.hex --force
RUN mix deps.get --force
RUN mix release
#Extract Release archive to /rel for copying in next stage
# Update app_name (clock) with real app name hereand in entrypoint
# (mind elixir project name from build stage)
ENV APP_NAME clock
RUN export RELEASE_DIR=`ls -d _build/prod/rel/$APP_NAME/releases/*/` && \
mkdir /export && \
tar -xf "$RELEASE_DIR/$APP_NAME.tar.gz" -C /export
#================
#Deployment Stage
#================
FROM erlang:alpine
RUN apk --update --no-cache add bash
#Set environment variables and expose port
EXPOSE 4000
ENV REPLACE_OS_VARS=true \
PORT=4000
#Copy and extract .tar.gz Release file from the previous stage
COPY --from=build /export/ .
#Set default entrypoint and command
ENTRYPOINT ["clock"]
CMD ["foreground"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment