Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active October 15, 2019 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cellularmitosis/91f654aca6500eb1c8408768486e19b8 to your computer and use it in GitHub Desktop.
Save cellularmitosis/91f654aca6500eb1c8408768486e19b8 to your computer and use it in GitHub Desktop.
Simple Clojure "Hello world" using leiningen

Blog 2019/7/17

<- previous | index | next ->

Simple Clojure "Hello world" using leiningen

Create a new single-file Clojure project using the main template (thanks to Ming Pan):

$ lein new main hello
$ cd hello

Run it:

$ lein run

Or start a REPL:

$ lein repl

and then execute the main function by typing (-main) into the REPL.

Dockerfile

You can also create a simple Dockerfile:

FROM clojure
COPY . /root
WORKDIR /root
CMD ["lein", "run"]

Build it:

$ docker build -t hello .

Run it:

$ docker run hello

You can speed this up a bit by generating an uberjar (thanks to Divyum Rastogi):

FROM clojure
COPY . /root
WORKDIR /root
RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar
CMD ["java", "-jar", "app-standalone.jar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment