The container image, shown only
A Java service ships as a jar and a runtime, and a container image is the two together. The Dockerfile of this project is seven lines: a JRE base image, the jar, the port, a health check and the entry point. It is shown and not built, because this container has no Docker daemon, and the page says what each line would do.
The image
The base is eclipse-temurin:21-jre-alpine: a Java 21 runtime without the compiler, on Alpine. A JRE is enough because the class files are already built; the JDK is a build tool and does not belong in the image. The tag names the version, which is the same discipline as naming a dependency version in a pom.
The Dockerfile
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY desk.jar /app/desk.jar
EXPOSE 8091
HEALTHCHECK --interval=30s --timeout=2s CMD wget -qO- http://127.0.0.1:8091/health || exit 1
ENTRYPOINT ["java", "-jar", "/app/desk.jar", "serve"]
Line by line
WORKDIR creates the folder and makes it the working directory, so the jar has a known path. COPY puts the jar built by the previous pages into the image; the build context is the folder with the jar, and a .dockerignore would keep the rest out. EXPOSE documents the port; it does not publish it, which is the -p of the run command. HEALTHCHECK runs a small command inside the container every thirty seconds and marks the container unhealthy after two seconds without an answer; wget is the busybox applet of the Alpine base.
ENTRYPOINT is the exec form, so the JVM is the first process of the container and receives the signal that stops it. The last argument is serve, which is the mode of the server page that starts the service and waits; without it the jar runs its self test and exits, which is right for a demonstration and wrong for a container.
The serve mode
java -jar desk.jar serve starts the server on 8091 and blocks on a latch that nothing counts down. A container that runs it stays up, the health check reaches /health, and docker stop sends SIGTERM to the JVM, which ends the process. That is the whole deployment contract of a service this small.
Why no image is built here
This container has no Docker daemon and no network to pull a base image, so the docker build command is not shown as run and no image is claimed. A machine with Docker would run docker build -t desk:1.0 . in the folder with the jar and the Dockerfile, then docker run -p 8091:8091 desk:1.0, and the health check would turn green after the first successful request. The page would then show the build output; here it shows the file and says what is missing.
The jar the Dockerfile copies is the one built with javac and jar on the packaging page. A build with Maven on a networked machine would put the same jar in target/, and the COPY line would name that path.
Where the group ends
This is the last page. The hub lists the eight pages, from the model to this file, and the Java course has the long form of each step: records and sealed types, the HTTP server, JUnit and the tools. The testing group covers the framework in full, and the Java and C++ group compares the language with the one this service could have been written in.
The service and its jar were built and run with OpenJDK 21.0.13 on Alpine Linux in a Docker container. The Dockerfile is shown and was not built: this container has no Docker daemon.
Article author: Arthur Isaev