Skip to content

Instantly share code, notes, and snippets.

@jalberto
Last active April 27, 2020 17:40
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 jalberto/fc3a6bce99c4904069eb37b49e06fac9 to your computer and use it in GitHub Desktop.
Save jalberto/fc3a6bce99c4904069eb37b49e06fac9 to your computer and use it in GitHub Desktop.
Elixir & Phoenix on Docker for development
  • The container expect your local user has uid:gid set as 1000
    • so when you run a command the files generated are not root owned
  • you can run any command like:
    • docker-compose run phx mix ecto.create
    • docker-compose run phx iex -S mix phx.server
    • docker-compose run phx mix phx.new . --app myproj
  • then run the server with docker-compose up
version: "3.2"
services:
phx:
image: myproj:latest
build: .
volumes:
- type: bind
source: .
target: /app
ports:
- "4000:4000"
depends_on:
- db
command: mix phx.server
db:
image: postgres:9.6
environment:
- POSTGRES_DB
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_HOST_AUTH_METHOD=trust
ports:
- "5432:5432"
volumes:
- pgvol:/var/lib/postgresql/data
# mailhog:
# image: mailhog/mailhog:latest
# ports:
# - "1025:1025"
# - "1080:1080"
# - "8025:8025"
volumes:
pgvol:
FROM elixir:1.10
ENV \
PHX_VER=1.5.1 \
NODE_VER=12.x \
APP=/app HOME=/app \
PKGS="inotify-tools postgresql-client git"
RUN groupadd -g 1000 appuser \
&& useradd -r -u 1000 -g appuser appuser \
&& mkdir -p $APP \
&& chown appuser:appuser $APP
RUN \
curl -sL https://deb.nodesource.com/setup_$NODE_VER | bash - \
&& curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update -qq \
&& apt-get install -qq $PKGS \
&& apt-get install -qq nodejs yarn \
&& apt-get clean \
&& rm -r /var/lib/apt/lists /var/cache/apt/archives
USER appuser
WORKDIR $APP
RUN \
mix local.hex --force \
&& mix local.rebar --force \
&& mix archive.install hex phx_new $PHX_VER --force
EXPOSE 4000
CMD ["iex"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment