Need help with alpine-erlang?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

208 Stars 7 Forks 66 Commits 9 Opened issues


Minimal Erlang/Elixir docker images with Alpine Linux

Services available


Need anything else?

Contributors list

# 97,675
63 commits

Erlang/Elixir on Alpine Linux

Alpine Linux is a lightweight Linux distribution built around musl libc and busybox. The main focus of this distribution is security, simplicity and resource efficiency. All that makes Alpine Linux perfect to work as base images for linux containers.

Minimal docker images

When creating a docker image, you probably want to minimize its size as much as possible. At the same time, you might want to have access to a full-featured package system with a large range of packages available. As far as I can see, Alpine Linux is the best choice for that.

How minimal?

REPOSITORY                     TAG      IMAGE ID       CREATED           VIRTUAL SIZE
hello                          latest   dfee0002c943   12 minutes ago    20.75 MB
hello_phoenix                  latest   0ea00b410d90   24 minutes ago    25.09 MB
msaraiva/elixir                1.2.0    df35f2590cd3   38 minutes ago    23.23 MB
msaraiva/erlang                18.1     55ac7fb64a42   56 minutes ago    18.3 MB

Getting started (WIP)


In order to keep packages as compact as possible, Erlang libraries for Alpine Linux are split into many different packages. The full list of Erlang packages available can be found here.

What is apk?


command is the official tool for package management on Alpine Linux. Something like
on Ubuntu. More information about
can be found here.

Installing packages with apk

Create a Dockerfile

FROM alpine:3.3

RUN apk --update add erlang && rm -rf /var/cache/apk/*

CMD ["/bin/sh"]

Build the image:

$ docker build -t erlang .


docker images
. You should see something like:
REPOSITORY           TAG           IMAGE ID           CREATED             VIRTUAL SIZE
erlang               latest        d76965a1f753       4 seconds ago       18.3 MB

Building packages

You can see how packages are built by looking at the APKBUILD scripts:

For more info, see


If you take a look at the APKBUILD scripts, you'll notice that some patches are applied in order to successfully build the packages. Some of those patches are related to musl, some to Busybox and some just split or remove stuff to make packages smaller. - Patches for Erlang

Docker Images

Note: All base images listed here are automated builds and their Dockerfiles can be found in the dockerfiles folder.


I'll describe here some examples on how to create minimal docker images for Erlang/Elixir projects using Alpine Linux.

Hello world (compilation on host machine)

A simple command line executable

  • Source:
  • Built with
  • Compilation on host machine
  • Requires Erlang 18.1 and Elixir >= 1.1.1 on the host machine
  • You need to compile your application on the host machine before building this image


FROM msaraiva/erlang:18.1

ADD hello /usr/local/bin/hello

ENTRYPOINT ["/usr/local/bin/hello"]


$ git clone
$ cd docker-alpine-examples/hello
$ MIX_ENV=prod mix
$ docker build -t hello .


docker images
. You should see something like:
REPOSITORY           TAG           IMAGE ID           CREATED             VIRTUAL SIZE
hello                latest        ab3d45ddf551       18 seconds ago      20.75 MB


$ docker run --rm hello Docker
Hello, Docker!

Hello world (compilation inside the container)

The same simple command line executable. But:

  • Compilation inside the container
  • No need to install Erlang/Elixir on the host machine


$ docker run --rm -v $PWD:$PWD -w $PWD -e "MIX_ENV=prod" msaraiva/elixir sh -c "mix"


$ docker run --rm hello Docker
Hello, Docker!

Phoenix + Elixir Release Manager (exrm)

In order to generate releases for phoenix applications, you need to make some minimal changes in a couple of files. See this page from the Phoenix documentation for details. If you just want to see the changes, take a look at this commit.

Another thing to pay attention to, is the architecture of the build environment. From the same Phoenix documentation:

We need to be sure that the architectures for both our build and hosting environments are the same, e.g. 64-bit Linux -> 64-bit Linux. If the architectures don't match, our application might not run when deployed.

By default,

pulls the Erlang runtime system from the build environment. That means, if you generate a release, for instance, on Windows or OSX, your application will not run on Alpine Linux. There are two ways to deal with this:
  1. Instruct
    to exclude the Erlang runtime from the release
  2. Gererate the release inside Alpine Linux

Note: To instruct

to exclude the Erlang runtime from the release, we need to create a file called
with this content:
{include_erts, false}.

Let's see how we can do this.

Hello Phoenix

This is the hello phoenix application created when you run

mix hello_phoenix --no-brunch --no-ecto


FROM msaraiva/erlang:18.1

RUN apk --update add erlang-crypto erlang-sasl && rm -rf /var/cache/apk/*

ENV APP_NAME hello_phoenix ENV APP_VERSION "0.0.1" ENV PORT 4000

RUN mkdir -p /$APP_NAME ADD rel/$APP_NAME/bin /$APP_NAME/bin ADD rel/$APP_NAME/lib /$APP_NAME/lib ADD rel/$APP_NAME/releases/ /$APP_NAME/releases/ ADD rel/$APP_NAME/releases/$APP_VERSION/$ /$APP_NAME/releases/$APP_VERSION/$ ADD rel/$APP_NAME/releases/$APP_VERSION/$APP_NAME.boot /$APP_NAME/releases/$APP_VERSION/$APP_NAME.boot ADD rel/$APP_NAME/releases/$APP_VERSION/$APP_NAME.rel /$APP_NAME/releases/$APP_VERSION/$APP_NAME.rel ADD rel/$APP_NAME/releases/$APP_VERSION/$APP_NAME.script /$APP_NAME/releases/$APP_VERSION/$APP_NAME.script ADD rel/$APP_NAME/releases/$APP_VERSION/start.boot /$APP_NAME/releases/$APP_VERSION/start.boot ADD rel/$APP_NAME/releases/$APP_VERSION/sys.config /$APP_NAME/releases/$APP_VERSION/sys.config ADD rel/$APP_NAME/releases/$APP_VERSION/vm.args /$APP_NAME/releases/$APP_VERSION/vm.args


CMD trap exit TERM; /$APP_NAME/bin/$APP_NAME foreground & wait


$ cd hello_phoenix
$ mix deps.get
$ MIX_ENV=prod mix compile
$ MIX_ENV=prod mix release
$ docker build -t hello_phoenix .


$ docker run --rm -p 4000:4000 hello_phoenix

Hello NIF

A simple command line executable that calculates a dot product of two lists on a NIF


$ cd hello_nif
$ docker run --rm -v $PWD:$PWD -w $PWD -e "MIX_ENV=prod" msaraiva/elixir-gcc sh -c "mix deps.get && mix"

Building the docker image:

$ docker build -t hello_nif .


$ docker run --rm hello_nif
Hello! This dot product was calculated by a NIF:
[1.0, 2.0, 3.0] x [5.0, 10.0, 20.0] = 85.0


Contributions are more than welcome. There're a lot of ways to contribute:

  • Compiling and testing other projects based on Erlang
  • Maintaining packages or creating new ones
  • Patching existing packages
  • Creating or improving docker images
  • Creating new examples
  • Improving this page

Feedback is also very important. If you have something to share, fell free to open an issue.


Related Projects

Other Resources and News

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.