Implement Docker deployment with Docker Compose

This commit is contained in:
pankaj 2024-09-06 18:15:09 +05:30
parent e24a6f6398
commit c1c7573c87
2 changed files with 43 additions and 19 deletions

10
Dockerfile Normal file
View file

@ -0,0 +1,10 @@
FROM openjdk:17-jdk-slim
WORKDIR /app
# Copy the application JAR file
COPY spring-petclinic-3.3.0-SNAPSHOT.jar /app/spring-petclinic.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "spring-petclinic.jar"]

View file

@ -1,25 +1,39 @@
version: '3.8'
services: services:
mysql: app:
image: mysql:8.4 image: spring-petclinic:latest
container_name: app
ports: ports:
- "3306:3306" - "8080:8080"
environment: environment:
- MYSQL_ROOT_PASSWORD= SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/petclinic
- MYSQL_ALLOW_EMPTY_PASSWORD=true SPRING_DATASOURCE_USERNAME: petclinic
- MYSQL_USER=petclinic SPRING_DATASOURCE_PASSWORD: petclinic
- MYSQL_PASSWORD=petclinic SPRING_PROFILES_ACTIVE: postgres
- MYSQL_DATABASE=petclinic depends_on:
volumes: - db
- "./conf.d:/etc/mysql/conf.d:ro" networks:
profiles: - app-network
- mysql
postgres: db:
image: postgres:16.3 image: postgres:16.3
container_name: db
environment:
POSTGRES_USER: petclinic
POSTGRES_PASSWORD: petclinic
POSTGRES_DB: petclinic
ports: ports:
- "5432:5432" - "5432:5432"
environment: volumes:
- POSTGRES_PASSWORD=petclinic - db-data:/var/lib/postgresql/data # Volume for PostgreSQL data persistence
- POSTGRES_USER=petclinic networks:
- POSTGRES_DB=petclinic - app-network
profiles:
- postgres networks:
app-network:
name: app-network
volumes:
db-data:
name: db-data