Running node.js in a Rocket Container

While there has been lots published on running statically compiled golang applications in a coreos/rocket container, I noticed that the interwebs came up blank when looking for examples of running node.js. This is my attempt to resolve that.

There are several ways to determine what libs are required to run an application. You can use ldd and strace to hunt them all down manually.  Since this was supposed to be a quick exploration I reached for Jailkit. While its original intent is to help setup chroot jails it also happens to work perfectly for our current situation.

I’ll wait here while you install the following tools:

Jailkit requires root so we’ll switch into root for the rest of the build process:

sudo su -

Then we’ll create the folder structure that we will build our image / container into:

mkdir -p node-layout/rootfs

Next we’ll lean on jk_cp to copy node and its friends into this new structure we created:

jk_cp /root/node-layout/rootfs /usr/bin/node

To create a container the spec requires us to create a /root/node-layout/manifest which is a json encoded file. The example below shows the required fields for a valid manifest:

Next we’ll use the example from the node.js homepage, saving it to /root/node-layout/rootfs/server.js

At this point we’re ready to compile the image using actool:

actool --debug build node-layout/ example-node.aci

The image we just generated can be validated using the actool again with the command:

As long as everything above was successful we. are. ready.

Run your new image!

rkt --debug run example-node.aci

Currently rocket is a prototype but its already showing A LOT of promise and I’m excited adopt it into the infrastructure running PineHQ!