Amir Chaudhry

thoughts, comments & general ramblings

Unikernels and Modularity at GlueCon 2016

Above are the slides from my talk at GlueCon today. Following the overview, I spend a little more time describing the benefits of having an ecosystem of libraries we can use for unikernels. The demo I gave this time was a little more involved and showed how we can build unikernels using your normal development approaches but then re-target the same application to different backends (i.e. for ARM and the Internet of Things).

Below are some details of how you can step through the demo for yourselves and you can find more information about unikernels over at


The following instructions use Docker for Mac, which is currently in beta, but should work with any Docker installation. In order to deploy to a Cubieboard2, you need to have a board set up and running Xen. You can follow the relevant instructions for details.

The 2048 game I used here was originally put together as a tutorial for teaching OCaml and using js_of_ocaml. If you’re interested, you can find more instructions and follow the tutorial yourself on over on the original repo.

Building the 2048 game for the Unix backend

I used Docker for Mac, together with pre-prepared Docker images to speed things up. Bear in mind that things change across beta releases so if the following doesn’t work, please tweet me.

The first thing to show is how you can do development by targeting unix and using the appropriate system libraries. The Docker image already has a clone of the repo so you can use that. To follow my steps from the demo:

# On your terminal
$ docker run -it -p 80:8080 amirmc/gluecon2016-unix bash

# Inside the container
$ eval `opam config env`
$ cd gluecon2016
$ mirage configure --unix --net socket
$ make
$ sudo ./mir-www

You’ll see that the tool runs some checks and tries to install any necessary components for the target — in this case the unix-related libraries.

Once you’ve completed the above steps, you can point your browser at localhost to see the site. Congratulations, you should see the unix-based version of the 2048 game! Try not to get too distracted by playing. The next step is to use the same code base to build an ARM-based unikernel that will run on the Cubieboard2.

Building 2048 for the ARM backend

You will again use Docker but this time with the ARM images, based on resin/armv7hf-debian (NB: This is not a cross-compilation step). You can build the Xen image in the container using Docker but in order to deploy, you’ll need the Cubieboard2 already set up. This time, you can clone the demo repo on your machine and mount it into the container. The steps from this part of the demo were:

# Clone the repo and mount it in the ARM container
$ git clone
$ cd gluecon16
$ docker run -it -v `pwd`:/src amirmc/gluecon2016-arm bash

# Inside the container
$ eval `opam config env`
$ cd /src
$ mirage configure --xen --dhcp=true --network=0 --no-opam
$ make

The --no-opam flag is used because the container already has the necessary packages and you can skip that check. The --network=0 is to override a default in the file.

You should now have a file on your Mac called mir-www.xen. This is the binary you need to copy over to the Cubieboard2. You’ll notice an additional file, www.xl, which contains some configuration and will also need to be copied over (you will need to update the path in that file). Once these files are on the Cubieboard2, then it’s a simple case of sudo xl create -c www.xl. The IP address of the unikernel will be displayed and you can navigate to <IP address>:8080 from your browser. You’re now playing the 2048 game from a unikernel being served from the Cubieboard2! During this re-targeting, none of the application code had to be changed, the appropriate system libraries were pulled in at the right time.

Although the above may seem quite involved, it does demonstrate how we can use the existing tools to to develop and deploy applications that span both the cloud and IoT. Over time, the tooling for unikernels will improve and mature so that all of the above will become much easier!

Other resources

To get involved in the development work, please do join the unikernel forum, the MirageOS devel list, and try out some of the examples for yourselves!

Thanks to Mindy for reviewing an earlier draft.