Elixir Phoenix development using Docker and Docker-Compose

Elixir Phoenix development using Docker and Docker-Compose

Benjamin Silva Herrera's photo
Benjamin Silva Herrera
·Nov 26, 2020·

2 min read

Quick and dirty, this is my recipe for local development of elixir phoenix apps using docker and docker-compose.

3 important files:

  • Dockerfile
  • docker-compose.yml
  • dev.exs


FROM bitwalker/alpine-elixir-phoenix:latest

# 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

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


version: '3.7'
    build: '.'
      - "4000:4000"
      - /opt/app/assets/node_modules
      - /opt/app/deps
      - .:/opt/app
      - db
      MIX_ENV: 'dev'
    image: postgres:alpine
      - 5432:5432

here we mount 3 volumes, the first two hold the deps so we don't recompile elixir deps or install npm packages every time we build or run the service. The last volume is our app itself, this way, changes reflect immediately without rebuilding or restarting the service.


config :yourapp, Yourapp.Repo,
  username: "postgres",
  password: "postgres",
  database: "yourapp_dev",
  hostname: "db",
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

Just make sure to override the hostname with db and use the default user and password for postgres.

after this you can do docker-compose build and the docker-compose up and head to http://localhost:4000 in your browser.

if you want to enter to the container that is running:

docker container ls -a

Find the one with the _web suffix, mine is myapp_web

A one liner to enter to it would be something like this:

docker exec -it $(docker ps | grep 'myapp_web' | awk '{print $1}') /bin/bash

Share this