Skip to content

Instantly share code, notes, and snippets.

@brentjanderson
Last active June 8, 2018 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentjanderson/aa4c59dd55f99320f30433d0fcaad683 to your computer and use it in GitHub Desktop.
Save brentjanderson/aa4c59dd55f99320f30433d0fcaad683 to your computer and use it in GitHub Desktop.
Example Dockerfiles for phoenix app packaged with distillery (Production ready image and testing image)

Note that these dockerfiles depend on:

  • Having Docker installed on your machine
  • Rebuilding the image every time you want to try your latest code
  • Passing necessary environment variables when you docker run
  • Your app includes distillery and coveralls

Make modifications as needed to meet those requirements.

Note that multi-stage builds can be used to combine the prod and test files described below, I haven't updated the gist yet to reflect that option.

Running without rebuilding

If you want to run without rebuilding, an easy approach would be to modify the test.Dockerfile to use the following CMD:

CMD ["mix", "phx.server"]

And to mount volumes into the container for rel, config, priv, test, lib, mix.{exs,lock} and anything else you need to run your app.

docker build -t my-app -f test.Dockerfile .
docker run --rm -v ./lib:/app/lib -v ./mix.exs:/app/mix.exs <repeat -v flags as needed> -e MIX_ENV=dev <repeat -e flags as needed> my-app
FROM elixir:1.6-alpine AS build
WORKDIR /app
ENV MIX_ENV=prod
COPY mix.exs mix.lock /app/
RUN mix do local.hex --force, local.rebar --force, deps.get
COPY rel rel
COPY config config
COPY priv priv
COPY test test
COPY lib lib
RUN mix do deps.compile, phx.digest
RUN mix release
FROM alpine:3.7
RUN apk --update --no-cache add bash openssl-dev
ENV PORT=80
EXPOSE ${PORT}
COPY --from=build /app/_build/prod /app
CMD ["/app/rel/your_app_name_here/bin/your_app_name_here", "foreground"]
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost/_healthcheck || exit 1
FROM elixir:1.6-alpine
WORKDIR /app
ENV MIX_ENV=test
COPY mix.exs mix.lock /app/
RUN mix do local.hex --force, local.rebar --force, deps.get
COPY rel rel
COPY config config
COPY priv priv
COPY test test
COPY lib lib
RUN mix do deps.compile, phx.digest
CMD ["mix", "coveralls"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment