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
2
2
FROM gradle:8.5-jdk21 AS build
3
+ # Copy source code into the container and set the ownership to 'gradle' user
3
4
COPY --chown=gradle:gradle . /home/gradle/src
4
5
WORKDIR /home/gradle/src
5
6
RUN gradle build -x test --no-daemon
6
7
8
+ # Stage 2: Production image
7
9
FROM openjdk:21-slim AS production
8
10
EXPOSE 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
10
19
COPY --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