(Docker+SpringBoot+Mysql) Mysql connection refused

Dipesh KC :

Problem Description

Spring Boot(app) container cant connect to "mysql" container

Problem Output

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

application.properties

spring.datasource.username = root
spring.datasource.url = jdbc:mysql://mysql:3306/fms?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
spring.datasource.password = [email protected]

docker-compose.yml

version: '3.7'
services:  
    mysql:
        image: mysql:latest
        restart: always
        command: --default-authentication-plugin=mysql_native_password
        ports:
            - "33061:3306"
        networks:
            - spring-boot-mysql-network
        environment:
            MYSQL_DATABASE: fms
            MYSQL_ROOT_PASSWORD: [email protected]
        volumes:
            - ./database_storage:/docker-entrypoint-initdb.d

    app:
        build:
            context: .
            dockerfile: app.Dockerfile
        ports: 
            - "8091:8080"
        networks:
            - spring-boot-mysql-network
        depends_on: 
            - mysql

    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        container_name: phpmyadmin
        restart: always
        depends_on: 
            - mysql
        environment: 
            PMA_HOST: database
            PMA_PORT: 3306
        ports:
            - "9091:80"

networks:
    spring-boot-mysql-network:
        driver: bridge
Dipesh KC :

I had done a silly mistake.

I was updating my application.property file and docker-compose up --build.But I never repackaged war file.So I was reading my old war file and thus reading my old property file

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related