sourceboat / docker-phoenix

A highly opinionated docker image which aims to be perfectly suited to run our Phoenix applications.
MIT License
8 stars 2 forks source link
alpine docker elixir erlang hacktoberfest phoenix

⚠️ Deprecated: This project is not actively maintained anymore.

docker-phoenix

An opinionated docker image which aims to be perfectly suited to run our Phoenix applications.

What's included?

Images for Development and Production

This project contains two Docker image variants:

In addition to the specific versions there are latest (based on the main branch) and edge (based on the develop branch) version tags available.

Note: You can check the Dockerfile or the releases page for info on the currently used versions of Elixir and Alpine.

Additional Startup Commands

You can add environment varialbles to run additional commands on container startup via the STARTUP_COMMAND_<XXX> syntax. This is useful for installing dependencies in development (see usage example below) or running database migrations in simple production setups.

Usage

You can use this Dockerfile as a starting point and adjust it to your needs:

########################################################################
# Stage: builder
########################################################################

FROM sourceboat/docker-phoenix:<version>-builder as builder

ARG MIX_ENV=prod
ENV MIX_ENV=$MIX_ENV

COPY mix.exs mix.lock ./
RUN mix do deps.get, deps.compile

COPY package.json yarn.lock ./
RUN yarn install --pure-lockfile

COPY webpack.mix.js tailwind.config.js ./
COPY assets assets/
COPY lib/my_app_web/templates lib/my_app_web/templates/
COPY lib/my_app_web/views lib/my_app_web/views/
RUN yarn prod

COPY . .

########################################################################
# Stage: release
########################################################################

FROM builder as release

ENV MIX_ENV=prod

RUN mix do deps.get, deps.compile, phx.digest, release --overwrite

########################################################################
# Stage: runtime
########################################################################

FROM sourceboat/docker-phoenix:<version>-runtime as runtime

ENV MIX_ENV=prod \
    RELEASE_NAME=my_app

COPY --from=release --chown=nobody:nobody /opt/app/_build /opt/app/_build
COPY --from=release --chown=nobody:nobody /opt/app/priv /opt/app/priv

USER nobody:nobody

For local development you can use the following docker-compose.yml file:

version: '3.7'
services:
  app:
    build:
      context: .
      target: builder
      args:
        MIX_ENV: dev
    env_file: .env
    environment:
      - STARTUP_COMMAND_1=mix deps.get
      - STARTUP_COMMAND_2=yarn install --pure-lockfile
    volumes:
      - .:/opt/app:delegated
    ports:
      - "4000:4000"
  postgres:
    image: postgres:12-alpine
    environment:
      - POSTGRES_PASSWORD=postgres
    ports:
      - 54321:5432

Changelog

Check releases for all notable changes.

License

The MIT License (MIT). Please see License File for more information.