Cannot connect to MariaDB instance from a Spring Boot instance using Docker Compose

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.


Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
echo "I am a code."
echo "An athletic one, and I wanna run."
```