docker from scratch in

I have been using for a couple of years now on various projects – just a Makefile, but what a Makefile! I’ve recently added a fork that includes support for creating docker containers from scratch.

On MacOS you might want to run shortishly/docker-erlang which will give you erlang and docker packaged together in a shell (brew install docker-machine if you don’t already have it):

docker run \
       -v /var/run/docker.sock:/var/run/docker.sock \
       -t \
       -i \
       --rm \
       shortishly/docker-erlang \

This is a short tutorial that assumes you are running on Linux, with both erlang and docker installed:

First lets create and move into a directory for this tutorial:

mkdir demo && cd demo

We need a copy of from the fork that I have created:

wget -q

Bootstrap a new project as you would do normally, including a release template:

make -f bootstrap
make bootstrap-rel

Also bootstrap this project to create a Docker container:

make bootstrap-docker

The “bootstrap-docker” target has created a Dockerfile for us:

FROM scratch


ENV BINDIR /erts-7.2.1/bin
ENV BOOT /releases/1/demo_release
ENV CONFIG /releases/1/sys.config
ENV ARGS_FILE /releases/1/vm.args


ENTRYPOINT exec ${BINDIR}/erlexec -boot_var /lib -boot ${BOOT} -noinput -config ${CONFIG} -args_file ${ARGS_FILE}

ADD _rel/demo_release/ /

Finally! Lets build the demo:


There should be lots of output at this point. At the end you should see:

===> Starting relx build process ...
===> Resolving OTP Applications from directories:
===> Resolved demo_release-1
===> Including Erts from /home/pmorgan/opt/erlang/18.2.1
===> release successfully created!
 GEN    docker-scratch-cp-dynamic-libs
 GEN    docker-scratch-cp-link-loader
 GEN    docker-scratch-cp-sh
 GEN    docker-strip-erts-binaries
 GEN    docker-build

A release has been successfully created “demo_release-1”, together with a bunch of new docker based targets and a new docker image (you will have a different sh256 output). You can check the output of docker images:

docker images

REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
demo_release               0.0.1               6440d984e0ef        3 minutes ago       22.02 MB

You can run the image with make docker-run:

make docker-run

 GEN    docker-rm
 GEN    docker-run

Again, you will have a different hash shown for the container that is now running – you can check that it is running with docker ps -a:

docker ps -a

CONTAINER ID        IMAGE                COMMAND                  CREATED              STATUS              PORTS               NAMES
b9deb1f7ef33        demo_release:0.0.1   "/bin/sh -c 'exec ${B"   About a minute ago   Up About a minute                       demo_release

You can use the shortcut make docker-logs to display the logs from your container:

make docker-logs

 GEN    docker-logs
heart_beat_kill_pid = 1

So with the help of we have been able to bootstrap an erlang project, building and running a docker container in about 10 shell commands.

Leave a Reply

Your email address will not be published. Required fields are marked *