Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"Hello, world" in Clojure compiled with GraalVM running in Docker

Blog 2019/7/18

<- previous | index | next ->

"Hello, world" in Clojure compiled with GraalVM running in Docker

Create a new minimal Clojure project using leiningen:

$ lein new minimal hello
$ cd hello

Edit project.clj to look like this:

(defproject hello "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.10.0"]]
  :profiles {:dev {:dependencies [[org.clojure/test.check "0.9.0"]]}} :main hello.core)

Edit src/hello/core.clj to look like this:

(ns hello.core
  (:gen-class))

(defn -main []
  (println "Hello, clombda!"))

According to this you also need to run this:

$ lein change :main set hello.core

Build a native image:

$ docker run --rm "-v$(pwd):/clj" "-v${HOME}/.m2:/root/.m2" spieden/clombda:latest

Create a Dockerfile:

FROM renanpalmeira/graalvm-alpine
COPY target/clombda/package/clj-native /root/
CMD ["/root/clj-native"]

Build a docker image:

$ docker build -t hello .

Run it:

$ docker run hello
Hello, clombda!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment