# Multi-stage build to compile the project with Maven and provide a minimal runtime image FROM maven:3.8.6-jdk-8 AS builder WORKDIR /build # Copy the pom and the source code to leverage Docker layer caching for dependencies COPY pom.xml ./ COPY src ./src # Build the project from source (skipping tests for a faster image build) RUN mvn -B -DskipTests package # Runtime stage FROM openjdk:8-jre-slim WORKDIR /app # Copy the built artifact from the builder stage COPY --from=builder /build/target/commons-csv-1.14.2-SNAPSHOT.jar /app/commons-csv-1.14.2-SNAPSHOT.jar # Provide a simple runtime behavior CMD ["bash", "-lc", "echo 'Apache Commons CSV built into image: /app/commons-csv-1.14.2-SNAPSHOT.jar'; tail -f /dev/null"]
# Multi-stage build to compile the project with Maven and provide a minimal runtime image FROM maven:3.8.6-jdk-8 AS builder WORKDIR /build # Copy the pom and the source code to leverage Docker layer caching for dependencies COPY pom.xml ./ COPY src ./src # Build the project from source (skipping tests for a faster image build) RUN mvn -B -DskipTests package # Runtime stage FROM eclipse-temurin:8-jre WORKDIR /app # Copy the built artifact from the builder stage COPY --from=builder /build/target/commons-csv-1.14.2-SNAPSHOT.jar /app/commons-csv-1.14.2-SNAPSHOT.jar # Provide a simple runtime behavior CMD ["sh", "-lc", "echo 'Apache Commons CSV built: /app/commons-csv-1.14.2-SNAPSHOT.jar'; sleep infinity"]
Concerns: Hard-coded artifact name in COPY from builder; if the Maven artifact name or version changes, the COPY may fail to build., CMD uses sleep infinity to keep the container alive; for a library image this is common but not active testing of runtime behavior. Smoke [PASS]: test -s /app/commons-csv-1.14.2-SNAPSHOT.jar Smoke [PASS]: ls -l /app/commons-csv-1.14.2-SNAPSHOT.jar