Skip to content

Commit 5a5da94

Browse files
Ashish MishraAshish Mishra
authored andcommitted
adding multistage docker file
1 parent 3ef77db commit 5a5da94

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
FROM maven:3.8.5-openjdk-17 AS JARBUILDER
2+
3+
WORKDIR build
4+
5+
COPY src src
6+
COPY pom.xml pom.xml
7+
8+
RUN mvn clean package -DskipTests
9+
10+
# above we are builing the project jar file and consuming it below to launch the application
11+
112
FROM bellsoft/liberica-openjre-alpine
213

314
WORKDIR springApplication/app
415

5-
COPY target/*.jar app.jar
16+
COPY --from=JARBUILDER build/target/*.jar app.jar
617

718
CMD ["java", "-jar", "app.jar"]
819

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ project-root/
3737
```sh
3838
git clone https://github.com/beneite/SpringBootBasics.git
3939
cd SpringWithDocker
40-
mvn clean package -DskipTests
4140
```
42-
> Running ```mvn clean package -DskipTests``` will create a SpringWithDocker-0.0.1-SNAPSHOT.jar file in target folder.
4341

4442
### 2️⃣ Build and Run Containers
4543

@@ -49,6 +47,8 @@ docker compose --profile entireApp up --build
4947
- `--profile entireApp` will spin up the tagged services with 'entireApp' only
5048
- `-d` runs containers in detached mode
5149
- `--build` forces a rebuild of the Spring Boot image
50+
- The docker compose will also take care of building the docker file/image.
51+
- The docker file used is a multistage where in stage 1st i am creating the .jar file using the same in 2nd stage to bring the application up.
5252

5353
### 3️⃣ Check Running Containers
5454

-66.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)