From bd4ca28f2ecc8eefe16cc54f5725eb1646578dca Mon Sep 17 00:00:00 2001 From: Abdul Ahad Date: Thu, 1 Aug 2024 14:02:53 +0400 Subject: [PATCH] added my dockerfile --- Dockerfile.dockerfile | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Dockerfile.dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile.dockerfile b/Dockerfile.dockerfile new file mode 100644 index 0000000..755d7bf --- /dev/null +++ b/Dockerfile.dockerfile @@ -0,0 +1,28 @@ +#Adding required system +FROM maven:3.8.1-openjdk-17 AS build + +# Set the working directory +WORKDIR /app + +# Copy the pom.xml and install dependencies +COPY pom.xml /app/ +COPY src /app/src + +#Run command +RUN mvn clean package -DskipTests + +# contents of the target +RUN ls -l target/ + +# Use OpenJDK for running the application +FROM openjdk:17-jdk-slim + +# Set the working directory +WORKDIR /app + +# Copy the built JAR file from the Maven build stage +COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar rihal-0.0.1-SNAPSHOT.jar +ENTRYPOINT ["sh", "-c","java", "-jar", "rihal-0.0.1-SNAPSHOT.jar"] + +# Expose the application port +EXPOSE 8080 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..141bf63 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +services: + mysql: + image: mysql + container_name: mysql + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: usersystem + MYSQL_PASSWORD: root + MYSQL_TCP_PORT: 3307 + ports: + - "3307:3307" + volumes: + - mysql_data:/var/lib/mysql + networks: + - demo-network + + application: + + build: + context: . + dockerfile: Dockerfile.dockerfile + container_name: userinfo + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3307/usersystem?useSSL=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: root + SPRING_JPA_HIBERNATE_DDL_AUTO: update + SPRING_JPA_SHOW_SQL: "true" + ports: + - "8080:8080" + depends_on: + - mysql + networks: + - demo-network + restart: on-failure +networks: + demo-network: + +volumes: + mysql_data: \ No newline at end of file