Skip to content
master
Switch branches/tags
Code

docker-clojure

This is the repository for the official Docker image for Clojure. It is automatically pulled and built by Stackbrew into the Docker registry. This image runs on OpenJDK 8, 11, and more recent releases and includes Leiningen, boot, and/or tools-deps (see below for tags and building instructions).

Leiningen vs. boot vs. tools-deps

The version tags on these images look like (openjdk-major-version-)lein-N.N.N(-distro), (openjdk-major-version-)boot-N.N.N(-distro), and (openjdk-major-version-)tools-deps(-distro). These refer to which version of leiningen, boot, or tools-deps is packaged in the image (because they can then install and use any version of Clojure at runtime). The lein (or lein-slim-bullseye, openjdk-14-lein, etc.) images will always have a recent version of leiningen installed. If you want boot, specify either clojure:boot, clojure:boot-slim-bullseye, or clojure:boot-N.N.N, clojure:boot-N.N.N-slim-bullseye, clojure:openjdk-14-boot-N.N.N-slim-bullseye, etc. (where N.N.N is the version of boot you want installed). If you want to use tools-deps, specify either clojure:tools-deps, clojure:tools-deps-slim-bullseye or other similar variants.

Note about the latest tag

As of 2020-3-20 the clojure:latest (also clojure because latest is the default) now has leiningen, boot, and tools-deps installed.

Previously this tag only had leiningen installed. Installing the others is helpful for quick start examples, newcomers, etc. as leiningen is by no means the de facto standard build tool these days. The downside is that the image is larger. But for the latest tag it's a good trade off because for anything real we have always recommended using more specific tags. No other tags are affected by this change.

JDK versions

Java has recently introduced a new release cadence of every 6 months and dropped the leading 1 major version number. As of 2019-9-25, our images will default to the latest LTS release of OpenJDK (currently 11). But we also now provide the ability to specify which version of Java you'd like via Docker tags:

JDK 1.8 tools-deps image: clojure:openjdk-8-tools-deps JDK 11 variant of that image: clojure:openjdk-11-tools-deps or clojure:tool-deps JDK 14 with the latest release of leiningen: clojure:openjdk-14 JDK 15 with boot 2.8.3: clojure:openjdk-15-boot-2.8.3

Linux distro

The upstream OpenJDK images are built on a few different variants of Debian Linux, so we have exposed those in our Docker tags as well. The default is now Debian slim-bullseye. But you can also specify which distro you'd like by appending it to the end of your Docker tag as in the following examples (but note that not every combination is provided upstream and thus likewise for us):

JDK 1.8 leiningen on Debian slim-bullseye: clojure:openjdk-8 or clojure:openjdk-8-lein or clojure:openjdk-8-lein-stretch JDK 1.8 leiningen on Debian buster: clojure:openjdk-8-buster or clojure:openjdk-8-lein-buster JDK 11 tools-deps on Debian slim-bullseye: clojure:tools-deps or clojure:openjdk-11-tools-deps or clojure:openjdk-11-tools-deps-slim-bullseye

Alpine Linux

Sometimes there are upstream openjdk images for early access JDK releases based on Alpine Linux, but they have often later been deprecated once that version is released.

As of 2021-09-08, there are alpine variants only for OpenJDK 18 early access.

Some example tags:

JDK 18 leiningen on Alpine: clojure:openjdk-18-alpine clojure:openjdk-18-lein-alpine JDK 18 tools-deps on Alpine: clojure:openjdk-18-tools-deps-alpine

clojure:slim-buster / clojure:slim-bullseye

These images are based on the Debian buster distribution but have fewer packages installed and are thus much smaller than the stretch or buster images. Their use is recommended.

Examples

Interactive Shell

Run an interactive shell from this image.

docker run -i -t clojure /bin/bash

Then within the shell, create a new Leiningen project and start a Clojure REPL.

lein new hello-world
cd hello-world
lein repl

Builds

The Dockerfiles are generated by the docker-clojure Clojure app in this repo.

You'll need the tools-deps distribution of Clojure installed to run the build. Often this just means installing the clojure package for your system.

The ./build-images.sh script will generate the Dockerfiles and build all of the images.

buildx

Note that you'll need to enable the new buildx feature and set as the default builder in the Docker daemon you're using to build the images. The build script uses some flags that require it.

You'll also need to create a builder container with docker buildx create --use in order to build images for all supported platforms (currently linux/amd64 and linux/arm64).

Read the docs here for more info.

Tests

The docker-clojure build tool has a test suite that can be run via the ./test.sh script.