Docker Imagesλ︎
Docker images provide a quick approach to trying services and different operating systems. An image can be used as the base for other images.
Selecting Imagesλ︎
Docker Official Images are highly recommended. Look for the Docker Official Image tag on the image page.
Docker Official Image meaning
An Official Docker Image means the configuration of that image follows the Docker recommended practices, is well documented and designed for common use cases.
There is no implication as to the correctness of tools, languages or service that image provides, only in the means in which they are provided.
However, if time was invested in creating an image good enough to pass the Docker review, then it has a higher probability of being a useful image that others that are not official.
Common Official Docker images include
- Alpine Linux minimal operating system (musl lib)
- Debian Linux or Ubuntu Linux operating system
- Clojure - built by the Clojure community, provides tools to build Clojure projects (Clojure CLI, Leiningen)
- OpenJDK - Eclipse temurin - built by the community - provides the Java run-time
- OpenJDK - Amazon Corretto is an OpenJDK distribution by Amazon AWS team, Amazon Corretto can also be installed for the local development environment
- Postgres open-source object-relational database management system
- Redis open-source, networked, in-memory, key-value data store with optional durability
- nginx open source reverse proxy & load balancing for HTTP, HTTPS, SMTP, POP3 & IMAP protocols, HTTP cache and a web server
- mariadb open source relational database by the original developers of MySQL and is much more efficient
Operating Systemsλ︎
Operating systems are the base for many other Docker images, providing essential tools required for all software.
Alpine Linux is ultra-minimal operating system. Debian and Ubuntu Linux are glibc based operating systems which are commonly used.
Operating System Image Tags
Image tag | compressed size |
---|---|
debian:bookworm-slim | 27.8 MB |
debian:bookworm | 47.29 MB |
alpine:latest | 3.24 MB |
ubuntu:latest | 28.17 MB |
Alpine Linuxλ︎
Alpine Linux images have a very small footprint and provide the essential tools for running services that do not depend on specific operating system packages.
As images are very small, resources used both locally and in stage and production environments are minimal. This can be a simple way to reduce costs and do more with far fewer resources.
Alpine Linux uses the pkg
tool for package management, to add tools and libraries to support a Dockerfile build stage if required.
Alpine uses musl libc rather than glibc so testing software run on top of Alpine is important. Java 16 release officially supports Alpine Linux using musl. If required, there are several options to running glibc software on Alpine.
Debian Linuxλ︎
Debian Linux is a completely free operating system.
bookworm
is the name for Debian Linux 12, the latest stable release.
Debian Slim image provides a glib based operating system with a relatively minimal size, although not as small as Alpine Linux.
Ubuntu Linux is built from Debian Linux, adding kernel patches, sudo adminstrative access and other enhancements.
OpenJDKλ︎
OpenJDK is the most commonly used run-time environment for Java and JVM languages (Clojure, Kotlin, Scala, Gradle, Jython, JRuby, etc.).
A permissive use and distribution license is provided by all OpenJDK image variants.
Eclipse Temurinλ︎
Eclipse temurin OpenJDK - official Docker image is built by the Java community and provides the Java run-time (Java Virtual Machine). Eclipse Temurin provides all Long Term Support (LTS) versions from Java 8 onward and current intermediate releases. Variants are available with Alpine Linux and a wide range of system architectures (amd64
, arm32v7
, arm64v8
, ppc64le
, s390x
, windows-amd64
)
Amazon Correttoλ︎
Amazon Corretto is an OpenJDK distribution by Amazon AWS team and may be an appropriate choice if relying on Amazon support.
Amazon Corretto can also be installed for the local development environment, providing a consistent run-time between development and production.
Custom built imageλ︎
OpenJDK can be built with a custom set of modules, optomising the size of a container used to run a Java or JVM service
jdeps
analyses a .class
file, directory or .jar
file and lists Java module dependencies.
Clojure Uberjar files built with tools.build use multi-release jars, so a Java release version should be specified to see the respective dependencies.
java --list-modules
lists the modules contained in the current Java environment.
Custom Java runtime using jlink in multi-stage container build
FROM eclipse-temurin:21 as jre-build
# Create a custom Java runtime
#(1)!
RUN $JAVA_HOME/bin/jlink \
--add-modules java.base \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime
# Define base image
FROM debian:bookworm-slim
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-build /javaruntime $JAVA_HOME
# Continue with application deployment
--compress=2
option for Jlink uses Zip compression
If the JVM based application is still evolving it may be prudent to include the Jdeps command within the Jlink command
FROM eclipse-temurin:21 as jre-build
# Create a custom Java runtime
#(1)!
RUN $JAVA_HOME/bin/jlink \
--module-path practicalli-todo-uber.jar \
--add-modules $(jdeps --ignore-missing-deps \
--multi-release 21 \
--print-module-deps practicalli-todo-uber.jar) \
--no-header-files \
--no-man-pages \
--strip-debug \
--compress=2 \
--output /javaruntime
# Define base image
FROM debian:bookworm-slim
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"
COPY --from=jre-build /javaruntime $JAVA_HOME
# Continue with application deployment
jlink - Oracle Java SE help center
jlink - Assembel & Optomise Modules
jdeps - Oracle Java SE help center
Modules - Java 17 API Specification
Clojureλ︎
Clojure - official Docker Image - built by the Clojure community, provides tools to build Clojure projects (Clojure CLI, Leiningen)
Use the Clojure image within a Dockerfile
, specifying tools-deps
or lein
variants
The Clojure image is built from the equivalent Eclipse Temurin image which can be used as the run-time image for a Multi-stage Dockerfile final stage. As the build and final stages are built upon the same underlying image, a separate base stage is not required.
Clojure - official Docker Image
Multi-stage Dockerfile for Clojure
Clojure image tagsλ︎
Image tag | compressed size |
---|---|
temurin-17-tools-deps-bookworm-slim | 234.56 MB |
temurin-21-tools-deps-bookworm-slim | 247.68 MB |
temurin-17-tools-deps-alpine | 178.96 MB |
temurin-21-tools-deps-alpine | 191.89 MB |
Consider building a custom Java JDK to reduce the image size
MegaLinterλ︎
MegaLinter greatly simplifies applying quality
The MegaLinter image is an example of a docker image that provides a large number of tools which otherwise need to be installed directly on the operating system.