-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile
More file actions
34 lines (23 loc) · 869 Bytes
/
Dockerfile
File metadata and controls
34 lines (23 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Stage 1: Build the application
FROM maven:3.8.5-openjdk-8-slim AS build
# Set the working directory inside the container
WORKDIR /app
# Copy the pom.xml file to the working directory
COPY pom.xml .
# Download dependencies (without building the project yet)
RUN mvn dependency:go-offline -B
# Copy the entire project source code to the working directory
COPY src ./src
# Package the application (build the JAR file)
RUN mvn clean package -DskipTests
# Stage 2: Run the application
FROM openjdk:8-alpine
# Set environment variables using the recommended format
ENV PROJECT_HOME=/opt/app
WORKDIR $PROJECT_HOME
# Copy the JAR file from the previous stage
COPY --from=build /app/target/spring-boot-mongo-1.0.jar $PROJECT_HOME/spring-boot-mongo.jar
# Expose port 8080
EXPOSE 8080
# Run the Spring Boot application
CMD ["java", "-jar", "./spring-boot-mongo.jar"]