Home:ALL Converter>Docker compose for mysql and spring app gives access denied

Docker compose for mysql and spring app gives access denied

Ask Time:2018-09-30T23:06:04         Author:Sajad

Json Formatter

I have a docker compose for MySQL + Spring boot app:

This is how my docker-compose.yaml looks like

version: "3.3"
services:
  docker-mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: 'pass'
      MYSQL_DATABASE: 'test'
    volumes:
      - /var/lib/mysql
    ports:
      - 3306:3306
  my-app:
    build: .
    depends_on:
      - docker-mysql
    ports:
      - 8080:8080
restart: on-failure

And this is my Dockerfile:

FROM openjdk:8
EXPOSE 8080
ADD /target/app-0.0.1.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]

This is the application.properties of my app:

spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://docker-mysql:3306/test?characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=none
spring.datasource.driverClassName=com.mysql.jdbc.Driver

But when i run the containers with docker-compose up application encounter with access denied:

Access denied for user 'root'@'172.20.0.3' (using password: NO)

In the log file, mysql created with an empty password!

[Warning] root@localhost is created with an empty password !

Author:Sajad,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52579127/docker-compose-for-mysql-and-spring-app-gives-access-denied
techtabu :

you following properties should be changed to use the user and pass, you defined in docker-mysql.\n\nspring.datasource.password=pass\n\n\nAlso, add the links option in your spring-boot app. \n\ndepends_on:\n - docker-mysql\nlinks:\n - docker-mysql\n\n\nI don't think it matters, but the examples on the documentation uses the password without quotes. If above fails, try that as well. ",
2018-09-30T15:23:02
yy