Skip to content

Commit

Permalink
improve docker example (#3796)
Browse files Browse the repository at this point in the history
- add python (needed for nodegyp rebuild, will display error otherwise)
- mkdir isn't needed, WORKDIR will create the directory if it doesn't
  exist
- combine commands where possible to reduce the amount of docker layers
- copy package*.json and install packages before doing the deploy so the
  install won't happen every time you modify a js/css file or other
  asset
- bash not needed, sh/ash is available
- install ncurses-libs, the app wouldn't start otherwise
- do the chown when /app is still empty and add chown to the copy
  command, this saves docker from creating a large layer (about 10Mb)
  just for the permission changes
- add a default cmd
- use apk --no-cache so the cache doesn't get added to the image
  • Loading branch information
otijhuis authored and Gazler committed Apr 26, 2020
1 parent b3b5f23 commit f462182
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions guides/deployment/releases.md
Expand Up @@ -175,10 +175,9 @@ Here is an example Docker file to run at the root of your application covering a
FROM elixir:1.9.0-alpine AS build
# install build dependencies
RUN apk add --update build-base npm git
RUN apk add --no-cache build-base npm git python
# prepare build dir
RUN mkdir /app
WORKDIR /app
# install hex + rebar
Expand All @@ -191,35 +190,38 @@ ENV MIX_ENV=prod
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get
RUN mix deps.compile
RUN mix do deps.get, deps.compile
# build assets
COPY assets assets
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
COPY priv priv
RUN cd assets && npm install && npm run deploy
COPY assets assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest
# build project
# compile and build release
COPY lib lib
RUN mix compile
# build release (uncomment COPY if rel/ exists)
# uncomment COPY if rel/ exists
# COPY rel rel
RUN mix release
RUN mix do compile, release
# prepare release image
FROM alpine:3.9 AS app
RUN apk add --update bash openssl
RUN apk add --no-cache openssl ncurses-libs
RUN mkdir /app
WORKDIR /app
COPY --from=build /app/_build/prod/rel/my_app ./
RUN chown -R nobody: /app
USER nobody
RUN chown nobody:nobody /app
USER nobody:nobody
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/my_app ./
ENV HOME=/app
CMD ["bin/my_app", "start"]
```

At the end, you will have an application in `/app` ready to run as `bin/my_app start`.

0 comments on commit f462182

Please sign in to comment.