DEV Community

Cover image for Personal note: Dokerize Elixir App
Burhanuddin Ahmed
Burhanuddin Ahmed

Posted on

Personal note: Dokerize Elixir App

After we have completed creating our Elixir CRUD app, now we want to wrap it into a container. We will use Docker which is a popular tool to container the app.

To container it, we need to create a dockerfile in root app.

We can add .dockerignore. It's optional but ok if we have it.

.dockerignore

# Elixir Artifacts
/_build/
/deps/
/doc/
/cover/
/.fetch
*.ez
APPNAME-*.tar
erl_crash.dump


# Node Artifacts
npm-debug.log
/assets/node_modules/
/priv/static/


# File uploads
/uploads
/test/uploads


# Docker only
/test/
/.iex.exs
Enter fullscreen mode Exit fullscreen mode

OK, after we add it now we can add dockerfile.

dockerfile

FROM elixir:1.15.1 as builder
WORKDIR /app
COPY . .
ENV MIX_ENV=prod
COPY lib ./lib
COPY mix.exs .
COPY mix.lock .
COPY config/prod.env.exs config/

RUN mix local.rebar --force \
    && mix local.hex --force \
    && mix deps.get \
    && mix release

EXPOSE 8081

CMD ["_build/prod/rel/todo_app/bin/todo_app", "start"]
Enter fullscreen mode Exit fullscreen mode

If we want more advanced dockerfile, we can use multi-stage build dockerfile. By using multi-stage build we can have lighter image because it will only contain Elixir distribution file.

But in this post, We will only provide single-stage build for more simplicity.

Happy Coding!!! 🍻

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay