Access denied for 'user'@'host' in Dokcer container

I created a development environment with Docker for my Spring Boot project. But when I run the container I got a error like Access denied for 'latte_admin'@'localhost' (Using Password: YES). Occurs with the app and also if I run a healthcheck for the DB in the container. The project was connected without problem outside containers. I deleted containers, volumes and images and recreated they, but the issue persists. docker-compose.yml
services:
latte:
build:
context: latte
dockerfile: Dockerfile
mem_limit: 512m
ports:
- "8080:8080"
environment:
- SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/latte_ice_cream?createDatabaseIfNotExists=true&serverTimezone=UTC
- SPRING_DATASOURCE_USERNAME=latte_admin
- SPRING_DATASOURCE_PASSWORD=example # Not real passwords, just placeholders
volumes:
- ./latte:/latte
restart: always
depends_on:
- mariadb

mariadb:
image: mariadb:10.11.13
ports:
- "3307:3306"
volumes:
- mariadb_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=example_root
- MYSQL_DATABASE=latte_ice_cream
- MYSQL_USER=latte_admin
- MYSQL_PASSWORD=example

volumes:
mariadb_data:
services:
latte:
build:
context: latte
dockerfile: Dockerfile
mem_limit: 512m
ports:
- "8080:8080"
environment:
- SPRING_DATASOURCE_URL=jdbc:mariadb://mariadb:3306/latte_ice_cream?createDatabaseIfNotExists=true&serverTimezone=UTC
- SPRING_DATASOURCE_USERNAME=latte_admin
- SPRING_DATASOURCE_PASSWORD=example # Not real passwords, just placeholders
volumes:
- ./latte:/latte
restart: always
depends_on:
- mariadb

mariadb:
image: mariadb:10.11.13
ports:
- "3307:3306"
volumes:
- mariadb_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=example_root
- MYSQL_DATABASE=latte_ice_cream
- MYSQL_USER=latte_admin
- MYSQL_PASSWORD=example

volumes:
mariadb_data:
Dockerfile
FROM openjdk:24-jdk

RUN microdnf install findutils

WORKDIR /latte

EXPOSE 8080

ENTRYPOINT ["./gradlew", "bootRun"]
FROM openjdk:24-jdk

RUN microdnf install findutils

WORKDIR /latte

EXPOSE 8080

ENTRYPOINT ["./gradlew", "bootRun"]
application.yml
spring:

application:

name: latte

datasource:

url: "${SPRING_DATASOURCE_URL}"
username: "${SPRING_DATASOURCE_USERNAME}"
password: "${SPRING_DATASOURCE_PASSWORD}"

hikari:

initialization-fail-timeout: 60000
connection-timeout: 60000

jpa:

database-platform: org.hibernate.dialect.MariaDBDialect

hibernate:

ddl-auto: update

show-sql: true

server:

servlet:

context-path: /latte/api/v1
spring:

application:

name: latte

datasource:

url: "${SPRING_DATASOURCE_URL}"
username: "${SPRING_DATASOURCE_USERNAME}"
password: "${SPRING_DATASOURCE_PASSWORD}"

hikari:

initialization-fail-timeout: 60000
connection-timeout: 60000

jpa:

database-platform: org.hibernate.dialect.MariaDBDialect

hibernate:

ddl-auto: update

show-sql: true

server:

servlet:

context-path: /latte/api/v1
3 Replies
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @Franscis123$#! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
MdS
MdS3w ago
Have you tried connecting to your database as root user?
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?