Skip to content

Commit dccb067

Browse files
authored
Dockerfile for sample java programs
1 parent 452606c commit dccb067

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Stage 1: Build the application
2+
FROM maven:3.8.5-eclipse-temurin-11 AS build
3+
4+
# Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# Copy only the module-specific files
8+
ARG module
9+
COPY $module/pom.xml ./pom.xml
10+
COPY $module/src ./src
11+
12+
# Build the application
13+
RUN mvn clean package -DskipTests
14+
15+
# Stage 2: Package the application in a lightweight runtime
16+
FROM openjdk:11-jre-slim
17+
18+
# Set the working directory inside the container
19+
WORKDIR /app
20+
21+
# Copy the JAR file from the build stage
22+
COPY --from=build /app/target/*.jar ./app.jar
23+
24+
# Expose the application port (if applicable)
25+
EXPOSE 8080
26+
27+
# Command to run the application
28+
CMD ["java", "-jar", "app.jar"]

0 commit comments

Comments
 (0)