Skip to content

Commit bb67518

Browse files
add Dockerfile for building and running Java application with OpenJDK 17
1 parent 9640b7d commit bb67518

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

copilot-demo/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
11
# Build a java application image based on openjdk 17 and run it on port 8080
2+
3+
# Stage 1: Build the application
4+
FROM maven:3.9-eclipse-temurin-17 AS build
5+
WORKDIR /app
6+
COPY pom.xml .
7+
COPY src ./src
8+
RUN mvn clean package -DskipTests
9+
10+
# Stage 2: Run the application
11+
FROM eclipse-temurin:17-jre
12+
WORKDIR /app
13+
COPY --from=build /app/target/*.jar app.jar
14+
15+
# Create a non-root user and group, change ownership of /app, and switch to this user
16+
RUN addgroup --system javauser && adduser --system --ingroup javauser javauser && chown -R javauser:javauser /app
17+
USER javauser
18+
EXPOSE 8080
19+
ENTRYPOINT ["java", "-jar", "app.jar"]

0 commit comments

Comments
 (0)