JovaniPink

JovaniPink

Adding Solid Docker Compose Recipes

I just saw the announce of Awesome-Compose, “a Github repository with application samples” using Docker Compose.

Announcement Blog:
Awesome Compose for Sample Apps

Actual Git Repo:
Awesome-Compose

I thought it would be a great community effort if we added solid, regularly used, and popular docker compose recipes to the list.

Could you’all send me links or guides me to any examples that the community uses so we could add.

Thank you and for your support!

PS: I’m just starting off with Elixir and Phoenix and this would be super beneficial for me. :slight_smile:

Most Liked

akoutmos

akoutmos

Author of Build a Weather Station with Elixir and Nerves

I leverage Docker Compose for most of my tutorials on my blog. Below is a listing of the tech stacks, articles, and repos for each of the tutorials:

Prometheus, PostGIS and Phoenix Part 1
Article: Prometheus, PostGIS and Phoenix Part 1-Alex Koutmos | Engineering Blog
Repo: GitHub - akoutmos/elixir_monitoring_prom: Companion code for https://akoutmos.com/post/prometheus-postgis-and-phoenix/ · GitHub
Tech Stack: Elixir app, Postgres+PostGIS, Grafana, Prometheus, Postgres Exporter

Broadway, RabbitMQ, and the Rise of Elixir Part 1
Article: Broadway, RabbitMQ, and the Rise of Elixir Part 1-Alex Koutmos | Engineering Blog
Repo: GitHub - akoutmos/elixir_popularity: Companion code for https://akoutmos.com/post/broadway-rabbitmq-and-the-rise-of-elixir/ · GitHub
Tech Stack: cAdvisor, RabbitMQ, Postgres, Postgres Exporter, Grafana, Prometheus

Structured logging in Elixir using Loki
Article: Structured logging in Elixir using Loki-Alex Koutmos | Engineering Blog
Repo: GitHub - akoutmos/auto_finder: Companion code for https://akoutmos.com/post/elixir-logging-loki/ · GitHub
Tech Stack: Elixir app, Postgres, Loki, Grafana

And finally, while not Docker Compose specific, how to build Mix Releases with Docker:

Multi-stage Docker Builds and Elixir 1.9 Releases
Article: Multi-stage Docker Builds and Elixir 1.9 Releases-Alex Koutmos | Engineering Blog
Repo: GitHub - akoutmos/docker_elixir_19_release: Companion code for https://akoutmos.com/post/multipart-docker-and-elixir-1.9-releases/ · GitHub

gregvaughn

gregvaughn

In contrast I am quite comfortable with Elixir and Phoenix but I’m a novice at Docker. My main impression comes from all the people having problems with it. Knowing that solid recipes exist would be a huge benefit.

JackMaarek

JackMaarek

I have one docker-compose.yml file that build the phoenix container for backend and a elm app container for front-end:

You can access the repo here : GitHub - HETIC-MT-P2021/aio-group3-proj01: Elm application with Phoenix API on Docker : Edwin Vautier - Jack Maarek - Jason Gauvin · GitHub

Here is the docker-compose.yml:

version: '3.7'

services:
  db:
    image: postgres:9.6
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGDATA: /var/lib/postgresql/data/pgdata
    restart: always
    volumes:
      - ./pgdata:/var/lib/postgresql/data
  phoenix:
    build: .docker/backend/.
    volumes:
    - ./source/backend/api_app:/backend
    - .docker/backend/phoenix-setup.sh:/phoenix-setup.sh
    command: ../phoenix-setup.sh
    environment:
      PGUSER: postgres
      PGPASSWORD: postgres
      PGDATABASE: database_name
      PGPORT: 5432
      PGHOST: db
    ports:
      - 4000:4000
    depends_on:
      - db
  elm-app:
    build: .docker/frontend/.
    volumes:
      - ./source/frontend/:/elm-app
    command: elm reactor
    ports:
      - 8000:8000
    depends_on:
      - phoenix
volumes:
  pgdata:

The Docker file for backend api:

FROM elixir:latest

LABEL maintainer="Edouin Vautier, Jason Gauvin, Jack Maarek <https://github.com/HETIC-MT-P2021/aio-group3-proj01>"


RUN mix local.hex --force &&\
    mix local.rebar --force &&\
    mix archive.install hex phx_new 1.4.16 --force

RUN apt-get update && \
  ## install inotify-tool for phoenix hot reload
  apt-get install -y inotify-tools && \
  # Install postgres client
  apt-get install -y postgresql-client && \
  # Clear apt cache
   rm -rf /var/lib/apt/lists/*

WORKDIR /backend

EXPOSE 4000

with a setup shell file :

#!/usr/bin/env bash

mix deps.get # install project depencies
mix ecto.create
mix ecto.migrate  
exec mix phx.server

And the dockerfile for frontend:

FROM alpine:latest

RUN mkdir /elm-app
WORKDIR /elm-app

# Install curl package
RUN apk update && apk add --update curl && apk add --update nodejs npm && \
    # Install elm
    curl -L -o elm.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz && \
    gunzip elm.gz && \
    chmod +x elm && \
    mv elm /usr/local/bin/

EXPOSE 8000

Last Post!

Exadra37

Exadra37

The shadowing issue is only an issue if you run mix deps.get and mix compile in both the host and the container, otherwise is a non issue. If you run in both than you just need to map each folder in your root project and leave out the deps, _build and I think the assets/node_modules folders.

This is a completely different issue, and is nothing related with shadowing, instead it means you are missing the OS dependencies to build bccrypt in the container or if you are running mix commands in both the host and in the container, then it may cause issues, because bcrypt was compiled for a different target, but without seeing the exact error is hard to say.

To resume if you don’t run mix commands in both the container and host, shadowing is a non issue.

Docker Stack

Dockerfile

The Dockerfile now as non root user with the id 1000. Please read the comments in the Dockerfile to see if you need to customize this id for your computer.

ARG TAG=latest

FROM elixir:${TAG}

ARG PHOENIX_VERSION=1.4.16

RUN apt-get update && \

  ## install inotify-tool for phoenix hot reload
  apt-get install -y inotify-tools && \
  # DO THE SAME IN YOUR HOST MACHINE
  printf "fs.inotify.max_user_watches=524288\n" > /etc/sysctl.d/01-inotify.conf && \

  # install nodejs and npm on globaly
  curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
  apt-get install -y -q nodejs && \

  # Add the user `developer` with id `1000`. Adjust `1000` to match the user in
  #  your host in order to avoid permissions issues between container and host.
  # To check user id in host, just run: `id -u`
  useradd -m -u 1000 -s /bin/bash developer && \
  su developer -c 'mkdir -p /home/developer/phoenix' && \

  # Install postgres client
  apt-get install -y postgresql-client && \
  # Clear apt cache
  rm -rf /var/lib/apt/lists/*

USER developer

RUN mix local.hex --force &&\
    mix local.rebar --force &&\
    mix archive.install hex phx_new ${PHOENIX_VERSION} --force

WORKDIR /home/developer/phoenix

CMD ["bash"]

You can now build any combination of Elixir and Phoenix version:

docker build --build-arg "TAG=1.10" --build-arg "PHOENIX_VERSION=1.5.1" -t phoenix:1.10_1.5.1 .

Docker Compose

I don’t have Elixir installed in my host, therefore I cannot test this docker compose file, but if I have not missed anything it will allow you to run mix commands from the host and container without causing issues:

# DONT USER VERSION £ UNLESS YOUR ARE USING DOCKER SWARM TO RUN THE CONTIANERS
version: '2.3'

services:
  db:
    image: postgres:9.6
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGDATA: /var/lib/postgresql/data/pgdata
    restart: always
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      # IF POSTGRES IS ONLY USED BY THE PHOENIX SERVICE THEN YOU CAN REMOVE THIS PORT MAP
      # This is listening to requests coming from outside your computer:
      #- "5432:5432"
      # Localhost only
      - "127.0.0.1:5432:5432"
  phoenix:
    build: .
    volumes:
      - $PWD/assets/css:/home/developer/phoenix/assets/css
      - $PWD/assets/js:/home/developer/phoenix/assets/js
      - $PWD/assets/static:/home/developer/phoenix/assets/static
      - $PWD/assets/package.json:/home/developer/phoenix/assets/package.json
      - $PWD/assets/package-lock.json:/home/developer/phoenix/assets/package-lock.json
      - $PWD/assets/webpack.config.js:/home/developer/phoenix/assets/webpack.config.js
      - $PWD:/home/developer/phoenix/config
      - $PWD:/home/developer/phoenix/lib
      - $PWD:/home/developer/phoenix/priv
      - $PWD/mix.exs:/home/developer/phoenix/mix.exs
      - $PWD/mix.lock:/home/developer/phoenix/mix.lock
      - $PWD/.formatter.exs:/home/developer/phoenix/.formatter.exs
    
    # DONT KNOW WHAT IS DOING BUT PROBABLY YOU WANT TO ADJUST IT FOR THE NEW STACK.
    #command: ../phoenix-setup.sh
    command: mix phx.server
    environment:
      PGUSER: postgres
      PGPASSWORD: postgres
      PGDATABASE: portfolio
      PGPORT: 5432
      PGHOST: db
    ports:
      # Only visible to localhost, otherwise will be 0.0.0.0, meaning it will listen to requests coming from outsiide.
      - "127.0.0.1:4000:4000"
    depends_on:
      - db
volumes:
  pgdata:

Where Next?

Popular in Discussions Top

CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -&gt; H; nth(N, [_|T]) when N &gt; 1 -&gt; nth(N - 1, T). Elixir Enum.at … coo...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31707 143
New
jesse
Hi everyone, I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New

Other popular topics Top

nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement