If I just start an Erlang shell it uses about 37 MB of memory (as shown by erlang:memory(total)) and then another 13 MB in caches and pre-allocated memory (docker stats shows 50 MB of memory usage). To get that value down a bit I can start erl like this:
Using -mode minimal disables some kernel services mostly related to distribution and timers. I thought it was documented by apparently not. It has minimal effect on memory usage, but it does shave a few KBs off as a couple of processes are not started.
We just did a similar exercise with an Elixir app. We used Burrito to create a single executable that contains erts and the beam files (Erlang/Elixir/the app). The Docker image size went from 200MB down to 20MB.
We did a 2 phase build.
Create a standard Dockerfile that creates a executable and an Elixir (mix) release.
A minimized Dockerfile that just takes the executable and libraries required and produces a small image.
You could probably use a rebar3 deployable tarball instead of Burrito and mix release.
Thanks a lot @nhpip. We use rebar3 of course for our Erlang releases and everything is working perfectly. Our images aren’t that small (~80MiB because we ship a code + many NIFs), but it’s OK.
My issue is with the .ez modules per @garazdawi suggestion.