Docker image for Erlang VM with minimal memory/disk usage

Hi guys,

Is there any Docker image I can use to build the smallest Erlang VM in term of memory usage and disk space?

Currently, I’m shipping my containers based on Ubuntu 22.04 LTS. They are pretty large and consume +200MB of RAM during startup (not even under load).

My task in the next weeks is to deploy more containers, and I can’t afford wasting memory like that.

Disclaimer: newbie here. I know only basics Docker.

Many thanks

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:

docker run -it erlang:26 erl +S 1 +SDio 1 +P 1024 +Q 1024 -mode minimal

That brings the memory usage down to 11 MB with 9 MB in caches etc, but it puts some constraints on the system that you might not want.

To decrease the amount of diskspace used, you should go for a multistage docker build where you only copy over your release. Like what is done here: GitHub - erlang/docker-erlang-example: HowTo Erlang in Docker and specifically in this Dockerfile.

4 Likes

@garazdawi thanks a lot. Let me give it go

Jade Allen talks about it in this presentation Code as infrastructure in the BEAM ecosystem - Jade Allen | Code BEAM Europe 2023 :slight_smile:

2 Likes

@garazdawi Is this still the case, or has the problem already been solved?

I came across this after reading Elixir question:
Using Alpine and musl instead of GNU libc affect performance?

@garazdawi -mode minimal seems undocumented. Is there any available information on what it does?

2 Likes

If you read the last comment of that issue you can see that it had nothing to do with using musl and yes it has been fixed.

1 Like

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.

1 Like