Skip to content

Instantly share code, notes, and snippets.

@wmnnd
Last active June 19, 2019 14:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wmnnd/dfc888e965a877e247a7c8f5ad3dab1c to your computer and use it in GitHub Desktop.
Save wmnnd/dfc888e965a877e247a7c8f5ad3dab1c to your computer and use it in GitHub Desktop.
Elixir Dockerfile Boilerplate
#===========
#Build Stage
#===========
FROM bitwalker/alpine-elixir:1.5 as build
#Copy the source folder into the Docker image
COPY . .
#Install dependencies and build Release
RUN export MIX_ENV=prod && \
rm -Rf _build && \
mix deps.get && \
mix release
#Extract Release archive to /rel for copying in next stage
RUN APP_NAME="MY_APP_NAME" && \
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 pentacent/alpine-erlang-base:latest
#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/ .
#Change user
USER default
#Set default entrypoint and command
ENTRYPOINT ["/opt/app/bin/MY_APP_NAME"]
CMD ["foreground"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment