This is my application.properties
:
spring.application.name=library-springboot
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/library
spring.datasource.url=jdbc:mysql://db:3306/library
spring.datasource.username=Haebin
spring.datasource.password=0000
logging.level.org.springframework=info
logging.level.edu.library=debug
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true
spring.sql.init.mode=always
spring.jpa.defer-datasource-initialization=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.boot.allow_jdbc_metadata_access=false
spring.servlet.multipart.enabled=true
spring.servlet.multipart.location=C:\\upload
spring.servlet.multipart.max-request-size=30MB
spring.servlet.multipart.max-file-size=10MB
edu.library.upload.path=C:\\upload
Dockerfile
:
FROM openjdk:17-jdk-slim
WORKDIR /app
COPY build/libs/library-springboot-0.0.1-SNAPSHOT.war /app/library-springboot.war
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/library-springboot.war"]
docker-compose
:
services:
db:
image: mysql:8.0.37
environment:
MYSQL_ROOT_PASSWORD: {pw}
MYSQL_DATABASE: library
MYSQL_USER: {user}
MYSQL_PASSWORD: {pw}
ports:
- "3306:3306"
networks:
- app-network
app:
image: techstack4
environment:
- DB_HOST=db
- DB_PORT=3306
- DB_USER={user}
- DB_PASSWORD={pw}
- DB_NAME=library
- SPRING_DATASOURCE_URL=jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}
ports:
- "8080:8080"
depends_on:
- db
networks:
- app-network
networks:
app-network:
I’m trying to run my project using a local MySQL schema (without running an additional container for MySQL), but it is unable to connect to the database. Kindly help out please.