Minimal Erlang/Elixir docker images with Alpine Linux

835 views
Skip to first unread message

Marlus Saraiva

unread,
May 19, 2015, 1:40:22 AM5/19/15
to elixir-l...@googlegroups.com
Hi everyone.

I've recently created an Elixir package for Alpine Linux. Also recently, I updated Elixir and Erlang to versions 1.0.4 and 17.5, respectively.

In case you never heard of it, Alpine Linux is a lightweight Linux distribution built around musl libc and busybox.

With Alpine Linux you can create docker images for Elixir/Erlang applications consuming less than 19Mb. A Phoenix application can take less than 23Mb. That includes application files and all linux dependencies.

More info and examples can be found here:

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

The packages are still in the "testing" repository, so fell free to send any feedback so we can make sure the packages work properly before they get promoted to the main repository.

Cheers,
Marlus

Ben Wilson

unread,
May 19, 2015, 10:56:00 AM5/19/15
to elixir-l...@googlegroups.com
This is AWESOME. To be sure I've read the readme correctly, https://github.com/msaraiva/docker-alpine#hello-world-compilation-inside-the-container seems to indicate that I can do the project compilation on the docker image? Have you run into any issues with NIFs?

Frank Hunleth

unread,
May 19, 2015, 1:00:43 PM5/19/15
to elixir-l...@googlegroups.com
Cool. Did you need to patch Erlang to make it compile under musl? Last
time I tried it, there were a couple compile errors. I don't remember
either being too hard to make compile, but I didn't verify that my
fixes definitely worked. Do you know if any regression testing has
been done on the Erlang VM to make sure that there aren't any subtle C
library issues?

Anyway, I'm thrilled that you're doing this, since I've been
interested in switching to musl on Nerves (crosscompiled/embedded
Erlang project), but had been afraid of introducing hard-to-debug
issues.

-Frank
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-ta...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-talk/CAJvhf-nMHw%3DbbEpX5UY6-nqfhuHnVbi_deesT1uFT%2B%2BgE37ctA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Ben Wilson

unread,
May 19, 2015, 4:12:11 PM5/19/15
to elixir-l...@googlegroups.com
Also, are you using exrm purely for its packaging or do you also have a good way of handling hot code reloading with docker images?

Marlus Saraiva

unread,
May 19, 2015, 7:07:44 PM5/19/15
to elixir-l...@googlegroups.com
Just created a base image to compile projects with NIFs:

Also added a new example that use this image:

Keep in mind that this image is just the minimal environment needed to compile Elixir + NIFs. Other C libraries required by your NIFs must be added by you. As long as they are compatible with Alpine Linux, you should have no problem.

Have fun!

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.

Marlus Saraiva

unread,
May 19, 2015, 7:48:19 PM5/19/15
to elixir-l...@googlegroups.com
Sorry. I forgot to answer those:

2015-05-19 17:12 GMT-03:00 Ben Wilson <benwil...@gmail.com>:
Also, are you using exrm purely for its packaging or do you also have a good way of handling hot code reloading with docker images?

Usually, hot code reloading is not a requirement for me, so I always replace the container.



On Tuesday, May 19, 2015 at 1:00:43 PM UTC-4, Frank Hunleth wrote:
Cool. Did you need to patch Erlang to make it compile under musl? Last
time I tried it, there were a couple compile errors. I don't remember
either being too hard to make compile, but I didn't verify that my
fixes definitely worked.

All applied patches can be found here: 

Most of these patches were borrowed from Fedora: 
 
Do you know if any regression testing has
been done on the Erlang VM to make sure that there aren't any subtle C
library issues?

I've been using the packages for a couple of months and, so far, haven't running into any issue. But as you can see, the packages are still in the "testing" repository. It would be really great to have more people testing the packages with different projects. This way we could at least document any issue found and only then, move to the main repo.
 

Ben Wilson

unread,
May 19, 2015, 9:27:50 PM5/19/15
to elixir-l...@googlegroups.com
For the versions that talk about compiling on a different machine, what OS are you running for the compilation?

Ben Wilson

unread,
May 19, 2015, 9:36:24 PM5/19/15
to elixir-l...@googlegroups.com
Oh shoot you answer this, ignore me. For those who may be wondering: any Linux OS ought to work.

Frank Hunleth

unread,
May 20, 2015, 9:29:53 AM5/20/15
to elixir-l...@googlegroups.com
Hi Marlus,

On Tue, May 19, 2015 at 7:48 PM, Marlus Saraiva
<marlus....@gmail.com> wrote:
...
>
> All applied patches can be found here:
> http://git.alpinelinux.org/cgit/aports/tree/testing/erlang
>

Thanks. I've started exercising your patches in Nerves as well. Even
though I'm not using Alpine Linux, I would assume that we'll run into
common issues with musl and I'll let you know. Have you considered
sending "remove-private-unit32.patch" and "replace_glibc_check.patch"
upstream? Those seem like fixes that anyone using Erlang with musl
would need.

Also, just for kicks, here are some more stats. A Raspberry Pi 2 build
with Elixir is at now under 23 MB for me. This includes everything in
the root file system, a 2.8 MB Linux kernel and the 3.5 MB Raspberry
Pi bootloader files. I've not done any file system compression (quick
test trimmed ~6 MB) or looked into trimming the kernel and libraries
further, but these numbers are really encouraging. While it's
unnecessary to shrink the image much on an RPi, I think that things
are in range to try making something interesting with Elixir on one of
the 16-32 MB Flash "IoT" devices.

Thanks again for sharing your project!

Frank
> https://groups.google.com/d/msgid/elixir-lang-talk/CAJvhf-me5aFAVkiOB8KyjX6UfxxVUWiCCqozD0ohSpkDPSs3aQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Frank Hunleth
Troodon Software LLC
Embedded Software Development
http://troodon-software.com/

Marlus Saraiva

unread,
May 20, 2015, 12:46:45 PM5/20/15
to elixir-l...@googlegroups.com
Hi, Frank.

2015-05-20 10:29 GMT-03:00 Frank Hunleth <fhun...@troodon-software.com>:
Hi Marlus,

On Tue, May 19, 2015 at 7:48 PM, Marlus Saraiva
<marlus....@gmail.com> wrote:
...
>
> All applied patches can be found here:
> http://git.alpinelinux.org/cgit/aports/tree/testing/erlang
>

Thanks. I've started exercising your patches in Nerves as well. Even
though I'm not using Alpine Linux, I would assume that we'll run into
common issues with musl and I'll let you know. Have you considered
sending "remove-private-unit32.patch" and "replace_glibc_check.patch"
upstream? Those seem like fixes that anyone using Erlang with musl
would need.

Just to make sure the right person gets the credit. The patches you mentioned were submitted by John Regan, the maintainer of the Erlang package for Alpine Linux. Although I have contributed with minor patches to the this package, I'm only maintaining the Elixir one.
 

Also, just for kicks, here are some more stats. A Raspberry Pi 2 build
with Elixir is at now under 23 MB for me. This includes everything in
the root file system, a 2.8 MB Linux kernel and the 3.5 MB Raspberry
Pi bootloader files. I've not done any file system compression (quick
test trimmed ~6 MB) or looked into trimming the kernel and libraries
further, but these numbers are really encouraging. While it's
unnecessary to shrink the image much on an RPi, I think that things
are in range to try making something interesting with Elixir on one of
the 16-32 MB Flash "IoT" devices.

That sounds pretty cool!
 

Thanks again for sharing your project!

Thanks for the feedback.

Reply all
Reply to author
Forward
0 new messages