# Multi-stage build for Java Faker project # Stage 1: build with Maven FROM maven:3.6.3-jdk-8 AS builder WORKDIR /workspace # Copy POM and source so we can leverage Docker layer caching COPY pom.xml . COPY src ./src # Build the project (skip tests for quicker smoke build) RUN mvn -B -DskipTests package # Stage 2: runtime image FROM openjdk:8-jre-slim WORKDIR /app # Copy the built jar from the builder stage COPY --from=builder /workspace/target/javafaker-1.0.3-SNAPSHOT.jar /app/javafaker-1.0.3-SNAPSHOT.jar # Provide an interactive shell for inspecting the container CMD ["/bin/bash"]
# Multi-stage build for Java Faker project # Stage 1: build with Maven FROM maven:3.6.3-jdk-8 AS builder WORKDIR /workspace # Copy POM and source so we can leverage Docker layer caching COPY pom.xml . COPY src ./src # Build the project (skip tests for quicker smoke build) RUN mvn -B -DskipTests package # Stage 2: runtime image FROM openjdk:8-jre WORKDIR /app # Copy the built jar from the builder stage COPY --from=builder /workspace/target/javafaker-1.0.3-SNAPSHOT.jar /app/javafaker-1.0.3-SNAPSHOT.jar # Run the application by default CMD ["java", "-jar", "javafaker-1.0.3-SNAPSHOT.jar"]
# Multi-stage build for Java Faker project # Stage 1: build with Maven FROM maven:3.6.3-jdk-8 AS builder WORKDIR /workspace # Copy POM and source so we can leverage Docker layer caching COPY pom.xml . COPY src ./src # Build the project (skip tests for quicker smoke build) RUN mvn -B -DskipTests package # Stage 2: runtime image FROM maven:3.6.3-jdk-8 WORKDIR /app # Copy the built jar from the builder stage COPY --from=builder /workspace/target/javafaker-1.0.3-SNAPSHOT.jar /app/javafaker-1.0.3-SNAPSHOT.jar # Run the application by default CMD ["java", "-jar", "javafaker-1.0.3-SNAPSHOT.jar"]
# Avoid sending large/unnecessary files to docker build context .git .gitignore target/ **/target/ node_modules/ **/node_modules/ build/ out/ *.log *.class *.jar *.war *.ear *.iml *.idea/ *.settings/ .DS_Store
Concerns: Runtime stage uses maven:3.6.3-jdk-8 for the final image; this makes the final image larger than necessary. Consider using a smaller JRE/JDK base image (e.g., openjdk:8-jre) for the runtime stage. Smoke [PASS]: test -f /app/javafaker-1.0.3-SNAPSHOT.jar Smoke [PASS]: jar tf /app/javafaker-1.0.3-SNAPSHOT.jar | head -n 1 Smoke [PASS]: java -version