Skip to content

Commit

Permalink
added docker-multistage build instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse-Cameron committed Jan 20, 2019
1 parent e4b3948 commit 0f64751
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,57 @@ test

This will keep the payload smaller and will also avoid any issues when compiling dependencies.

### Multistage Docker Builds

You can also leverage [docker multistage build](https://docs.docker.com/develop/develop-images/multistage-build/) and [bitwalker/alpine-elixir](https://github.com/bitwalker/alpine-elixir) to lower your image size significantly.

An example is shown below:

```dockerfile
FROM bitwalker/alpine-elixir-phoenix:latest AS phx-builder

# Set exposed ports
ENV MIX_ENV=prod

# Cache elixir deps
ADD mix.exs mix.lock ./
RUN mix do deps.get, deps.compile

# Same with npm deps
ADD assets/package.json assets/
RUN cd assets && \
npm install

ADD . .

# Run frontend build, compile, and digest assets
RUN cd assets/ && \
npm run deploy && \
cd - && \
mix do compile, phx.digest

FROM bitwalker/alpine-elixir:latest

EXPOSE 5000
ENV PORT=5000 MIX_ENV=prod

COPY --from=phx-builder /opt/app/_build /opt/app/_build
COPY --from=phx-builder /opt/app/priv /opt/app/priv
COPY --from=phx-builder /opt/app/config /opt/app/config
COPY --from=phx-builder /opt/app/lib /opt/app/lib
COPY --from=phx-builder /opt/app/deps /opt/app/deps
COPY --from=phx-builder /opt/app/.mix /opt/app/.mix
COPY --from=phx-builder /opt/app/mix.* /opt/app/

# alternatively you can just copy the whole dir over with:
# COPY --from=phx-builder /opt/app /opt/app
# be warned, this will however copy over non-build files

USER default

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

## License

MIT

0 comments on commit 0f64751

Please sign in to comment.