Dockerfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # ---- Build Stage ----
  2. FROM erlang:21 AS app_builder
  3. # Set environment variables for building the application
  4. ENV MIX_ENV=prod \
  5. TEST=1 \
  6. LANG=C.UTF-8
  7. # Fetch the latest version of Elixir (once the 1.9 docker image is available you won't have to do this)
  8. RUN set -xe \
  9. && ELIXIR_DOWNLOAD_URL="https://github.com/elixir-lang/elixir/archive/v1.10.3.tar.gz" \
  10. && ELIXIR_DOWNLOAD_SHA256="f3035fc5fdade35c3592a5fa7c8ee1aadb736f565c46b74b68ed7828b3ee1897" \
  11. && curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \
  12. && echo "$ELIXIR_DOWNLOAD_SHA256 elixir-src.tar.gz" | sha256sum -c - \
  13. && mkdir -p /usr/local/src/elixir \
  14. && tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \
  15. && rm elixir-src.tar.gz \
  16. && cd /usr/local/src/elixir \
  17. && make install clean
  18. # Install hex and rebar
  19. RUN mix local.hex --force && \
  20. mix local.rebar --force
  21. # Create the application build directory
  22. RUN mkdir /app
  23. WORKDIR /app
  24. # Copy over all the necessary application files and directories
  25. COPY config ./config
  26. COPY lib ./lib
  27. COPY priv ./priv
  28. COPY mix.exs .
  29. COPY mix.lock .
  30. # Fetch the application dependencies and build the application
  31. RUN mix deps.get
  32. RUN mix deps.compile
  33. RUN mix phx.digest
  34. RUN mix release
  35. # ---- Application Stage ----
  36. FROM debian:stretch AS app
  37. ENV LANG=C.UTF-8
  38. # Install openssl
  39. RUN apt-get update && apt-get install -y openssl
  40. # Copy over the build artifact from the previous step and create a non root user
  41. RUN useradd --create-home app
  42. WORKDIR /home/app
  43. COPY --from=app_builder /app/_build .
  44. RUN chown -R app: ./prod
  45. USER app
  46. # Run the Phoenix app
  47. CMD ["./prod/rel/openpod/bin/openpod", "start"]