I have been struggling with this issue for weeks now and could really use some help. I’ve followed various solutions from different websites but nothing so far has worked. My application cannot connect to the database. Here is my application docker file:
FROM eclipse-temurin:17.0.5_8-jre-focal as builder
ENV JAR_NAME=app-0.0.1-SNAPSHOT.jar
ENV APP_NAME=app.jar
ENV APP_HOME=/usr/app
WORKDIR $APP_HOME
COPY ./build/libs/$JAR_NAME $APP_HOME/$APP_NAME
EXPOSE 8081
ENTRYPOINT [“java”,“-jar”,“/usr/app/app.jar”]
Here is the relevant portion of my application.yml file:
spring:
data:
rest:
base-path: /api
datasource:
password: password
username: cbodine
url: jdbc:mariadb://localhost:3306/articles
jpa:
database-platform: org.hibernate.dialect.MySQLDialect
generate-ddl: true
open-in-view: false
show-sql: true
hibernate:
ddl-auto: create-drop
properties:
hibernate:
dialect: org.hibernate.dialect.MariaDB103Dialect
globally_quoted_identifiers: true
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.yaml
security:
user:
name: cbodine
password: password
Finally, here is my docker.compose file:
services:
app:
build: app
ports:
- 8081:8081
# environment:
# - MYSQL_DATABASE=articles
# networks:
# - spring-mariadb
depends_on:
- db
# condition: service_healthy
links:
- db
db:
image: mariadb
restart: always
# secrets:
# - db-password
volumes:
# - db:/var/lib/mariadb/data
- db:/data/db
# networks:
# - spring-mariadb
environment:
- ‘MARIADB_DATABASE=articles’
- ‘MARIADB_PASSWORD=password’
- ‘MARIADB_ROOT_PASSWORD=other_password’
- ‘MARIADB_USER=cbodine’
ports:
- ‘3306:3306’
# healthcheck:
# test: [“CMD”, “curl”, “-f”, “http://localhost:4302”]
# interval: 30s
# timeout: 10s
# retries: 5
volumes:
db:
driver: local
networks:
spring-mariadb:
# driver: bridge
secrets:
db-password:
file: db/password.txt
The commented out code shows some of the various things I’ve tried, but so far no luck.