Elixir on Heroku with Docker Containers

It is possible to deploy your Elixir application on Heroku using the Elixir Buildpack . However, you may want to deploy using Docker on Heroku instead. Perhaps your application has complex setup or configuration needs. Or perhaps you already have a Docker-ified application and you don’t want to have to do extra work to convert it to buildpacks and Procfiles.

Heroku supports Docker via the Container Registry and Runtime. Here’s the process of getting it set up:

  1. Create a Heroku application with heroku create <app_name>.
  2. Set the Heroku stack to “container” heroku set:stack container. This enables the container functionality and ensures that Heroku doesn’t become confused if your project also contains other manifests (such as package.json or Gemfile).
  3. Set up your Docker environment to talk to Heroku’s Docker registry instead of the default Docker registry: heroku container:login.
  4. Build the image and push it to the Heroku registry: heroku container:push web.
  5. Deploy it to your dynos: heroku container:release web.
  6. Check your site and make sure everything works.
  7. If your application does not boot and logs the error message Shall I install Hex? (if running non-interactively, use "mix local.hex --force") [Yn] ** (Mix) Could not find an SCM for dependency :phoenix from <app_name>.Mixfile, you may have to make a small change to your Dockerfile.

For reference, here’s my full Dockerfile for my Phoenix application:

1 FROM elixir:1.8.0-alpine
3 RUN apk add make gcc libc-dev
5 ENV CC=gcc
6 ENV MIX_HOME=/opt/mix
8 RUN mix local.hex --force \\
9 && mix local.rebar --force
11 WORKDIR /root/app
13 ADD ./ /root/app/
15 EXPOSE 4000
17 ARG MIX_ENV=prod
18 RUN echo ${MIX_ENV}
20 ENV PORT=4000
22 RUN mix deps.get
23 RUN mix deps.compile
24 RUN MAKE=cmake mix compile
25 RUN mix phx.digest
27 CMD ["mix", "phx.server"]