Container image for everyday Clojure.
This is stock Clojure container image with minor tweaks and opinions:
-
It targets OpenJDK 11 and is based on Debian 10 (Buster).
-
Contains
tools.depsas a tool of choice for dependency managment. -
Uses non-root user by default.
UIDandGIDcan be both customized with Docker build args if you wish but Docker Hub hook sets it to sensible defaults (1000:1000). Thanks to this it is easy to share host directory$HOME/.m2with container and download dependencies only once without permission issues. -
Implements
rlwrapworkaround in such a way that you can callcljorclojurecommand passing any arguments. For example, to start a REPL withclojure.java-timedependency available use-Sdepsargument accordingly:$ sudo docker run --rm -it --detach-keys=ctrl-@\ -v "$HOME/.m2:/home/app-user/.m2"\ shellbro/clojure clj -Sdeps\ '{:deps {clojure.java-time {:mvn/version "0.3.2"}}}' -
It is strictly versioned. Every image tag has a Unix time suffix indicating its release time.
To have your Clojure REPL always at hand add the following function to your
.bashrc file. This function takes your EDN deps as an argument and makes
sure you didn't forget important docker run options for REPL to be fully
working (like --detach-keys without which docker will intercept readline
keybiding Ctrl-p).
function repl {
sudo docker run --rm -it --detach-keys=ctrl-@\
-v "$HOME/.m2:/home/app-user/.m2"\
shellbro/clojure clj -Sdeps "{:deps ${1:-{}}}"
}
This time, to quickly spawn your Clojure REPL with clojure.java-time
dependency just run:
$ repl '{clojure.java-time {:mvn/version "0.3.2"}}'
user=> (require '[java-time :as t])
nil
user=> (t/as (t/local-date) :year)
2020
Note that when using repl function :deps level is already in place for user
convenience.