File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1- # The below Docker code creates an executable jar and then creates an Docker Image out of it.
1+ # Stage 1: Build the jar
22FROM gradle:8.5-jdk21 AS build
3+ # Copy source code into the container and set the ownership to 'gradle' user
34COPY --chown=gradle:gradle . /home/gradle/src
45WORKDIR /home/gradle/src
56RUN gradle build -x test --no-daemon
67
8+ # Stage 2: Production image
79FROM openjdk:21-slim AS production
810EXPOSE 8080
9- RUN mkdir /app
11+
12+ # Create a non-root user and group (using 'appuser' as an example)
13+ RUN groupadd -r appgroup && useradd -r -g appgroup -m appuser
14+
15+ # Create the /app directory and set permissions
16+ RUN mkdir /app && chown appuser:appgroup /app
17+
18+ # Copy the jar file from the build stage into the production image
1019COPY --from=build /home/gradle/src/build/libs/*.jar /app/companieshouse-*.jar
11- ENTRYPOINT ["java" ,"-jar" ,"app/companieshouse-*.jar" ]
20+
21+ # Change to non-root user
22+ USER appuser
23+
24+ # Set the entrypoint to run the Java application
25+ ENTRYPOINT ["java" , "-jar" , "/app/companieshouse-*.jar" ]
You can’t perform that action at this time.
0 commit comments