Your first Dockerfile
Write a Dockerfile that packages an executable Java jar and starts it the right way.
Open this lesson in the learning hubKey points
FROMpicks the base,WORKDIRsets the directory,COPYbrings files in, ENTRYPOINT says what runs.- Use the exec form
ENTRYPOINT ["java","-jar","app.jar"]. The shell form wraps you in /bin/sh, which swallows SIGTERM. ENTRYPOINTis the command,CMDis its default arguments. Users override CMD easily and ENTRYPOINT rarely.EXPOSEis documentation. It publishes nothing,-pdoes that.- Run as a non-root
USER. Most bases default to root, and root in a container is root on your mounted volumes.
Example
# Dockerfile
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY target/app.jar app.jar
# unprivileged user, fixed uid so volume permissions stay predictable
RUN useradd --system --uid 10001 appuser
USER 10001
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
# build and tag it:
# docker build -t myapp:1.0 .
Exec-form ENTRYPOINT, non-root USER, one jar. That is a real Dockerfile.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Docker course, and every lesson in it is listed on the Docker contents page.