Build production-ready multi-stage Dockerfile for the backend #134
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
backend/Dockerfilecurrently runs./mvnw spring-boot:runagainst a bind-mounted source tree. This means:What to do
Replace
backend/Dockerfilewith a two-stage build:Stage 1 — Build (JDK + Maven): compile the source, resolve all dependencies, produce the fat JAR.
Stage 2 — Runtime (JRE only): copy the JAR from stage 1, nothing else. No Maven, no source, no JDK tools.
Additional hardening
RUN addgroup --system app && adduser --system --ingroup app app, thenUSER app).JAVA_OPTSenvironment variable so they can be overridden at deploy time without rebuilding the image.ENTRYPOINTshould use exec form (JSON array) to ensure signals (SIGTERM) are passed directly to the JVM, enabling graceful shutdown.CI impact
The
e2e-testsjob inci.ymlcurrently builds the JAR withmvnw clean package -DskipTestsand runs it directly withjava -jar. That job does not use Docker for the backend — so no CI changes are needed for the backend Dockerfile immediately.However, once a production image build + push step is added to CI (future), this Dockerfile will be the one used.
Acceptance criteria
docker build -t familienarchiv-backend .frombackend/produces an image with no Maven or JDK tooling in the final layer.docker run --env-file .env familienarchiv-backendstarts successfully and/actuator/healthreturnsUP.