Containerized script interpreters, including Julia

The ability to easily run containerized applications using rkt is quite intoxicating, and quickly leads on to an exploration of what applications are readily available. Docker Hub and Quay are worth exploring. Among those applications on Docker Hub are Julia and Ruby.

Noting the slightly non-standard security requirements needed by the Julia interpreter, we can configure rktrunner to run Julia using this configuration file snippet:

image = [
    "--seccomp", "mode=retain,@docker/default-whitelist,mbind",

image = "docker://julia"
exec = ["/usr/local/julia/bin/julia"]

Note that this snippet makes use of a rktrunner alias, so that we can invoke containerized Julia very easily.

$ rkt-run -i julia
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation:
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.1 (2017-03-05 13:25 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official release
|__/                   |  x86_64-pc-linux-gnu


The julia alias is defined to rktrunner by virtue of being the basename of the path /usr/local/julia/bin/julia given in the config file. As usual, if you want to see what rktrunner is actually passing through to the rkt run command, use rkt-run -v.

So far so good, but how to use this as a script interpreter?

Ideally, we would like to be able to simply run a Julia script simply by invoking it from the command line. Suppose the following file is called hello-world.jl, is executable, and is on the path:

#!/usr/bin/env julia
println("Hello Julia world!")

What do we need in place to be able to invoke it as hello-world.jl? We simply need an executable called julia installed somewhere on the path, which will be invoked with the name of the script file as an argument, and will in turn invoke rkt-run julia <scriptfile>.

In fact, rktrunner comes with just such an executable, called rkt-run-helper, which looks at its own name to determine which alias to use. So it is sufficient to setup a symlink called julia somewhere on the path, like this (exact details depending on where rkt-run-helper has been installed):

$ ls -l julia
lrwxrwxrwx 1 root root 37 Apr 20 12:08 julia -> /usr/libexec/rktrunner/rkt-run-helper

And once this is in place, we have just what we wanted, and can run Julia scripts using the containerized Julia interpreter.

$ ./hello-world.jl 
Hello Julia world!