From c0fcb68f5ffd8272965acb7f02c33a2267bb8cf0 Mon Sep 17 00:00:00 2001 From: Atharva Naphade Date: Sat, 6 Nov 2021 10:26:23 +0530 Subject: [PATCH] Updated --- Dockerfile | 33 +++++++++++++++++++++++++-------- README.md | 7 +++---- entrypoint.sh | 2 ++ run.sh | 4 ---- 4 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 entrypoint.sh delete mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile index 509570c..6b346a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,25 @@ -FROM openjdk:8-jdk-alpine -RUN addgroup -S spring && adduser -S spring -G spring -USER spring:spring -ARG DEPENDENCY=target/dependency -COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib -COPY ${DEPENDENCY}/META-INF /app/META-INF -COPY ${DEPENDENCY}/BOOT-INF/classes /app -ENTRYPOINT ["java","-cp","app:app/lib/*","com.application.scheduler.SchedulerApplication"] \ No newline at end of file +# Build Stage + +FROM maven:3.6.0 AS BUILD_STAGE +WORKDIR / +COPY . . +RUN ["mvn", "clean", "install", "-Dmaven.test.skip=true"] + +# Run Stage + +FROM openjdk:11.0.6-jre-slim +WORKDIR / + +USER root + +COPY --from=BUILD_STAGE /target/*.jar proj.jar + +RUN apt update && apt install -y docker.io + +ADD entrypoint.sh entrypoint.sh + +RUN chmod a+x ./entrypoint.sh + +EXPOSE 8080 + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/README.md b/README.md index f9d0317..ee4e4a8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ## Spring Boot and Docker

To run the application type the following commands.

- - sudo chmod +x run.sh - docker build -t spring-app . - docker run -e "JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n" -p 8080:8080 -p 5005:5005 -t spring-app \ No newline at end of file + + docker image build . -t proj + docker container run -p 8080:8080 /var/run/docker.sock:/var/run/docker.sock -t proj \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..fc8a7a6 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +java -jar proj.jar \ No newline at end of file diff --git a/run.sh b/run.sh deleted file mode 100755 index 17c6dab..0000000 --- a/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -mvn clean package -mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar) \ No newline at end of file