Home:ALL Converter>docker-compose mysql link issue with spring boot

docker-compose mysql link issue with spring boot

Ask Time:2016-07-20T21:01:39         Author:Ali Dufour

Json Formatter

Pretty similar issue raised in other questions on Stack Overflow but I can't seem to get my Dockerized Spring boot app to link to my dockerized mysql container with docker-compose

Here is my docker-compose file:

mysql:
    image: mysql/mysql-server:latest
    environment:
    - MYSQL_ROOT_PASSWORD=C4rdi0St4t!
    - MYSQL_DATABASE=icentia
    ports:
        - "3306:3306"
    expose:
        - "3306"    
    volumes:
     - /Users/Shared/data:/var/lib/mysql



tracking:
    image: icentia/tracking:latest
    ports:
        - "8083:8083"
        - "5053:5053" 
    links: 
        - mysql:icentiadb    

This is the jdbc connection string:

url: jdbc:mysql://icentiadb/icentia?autoReconnect=true&useSSL=false

also tried with:

url: jdbc:mysql://icentiadb:3306/icentia?autoReconnect=true&useSSL=false

If I start my spring boot app without running in a container ie though IDE and use localhost:3306, it works, so passing through the ports config of the mysql container is possible (meaning config is proper).

This is from Docker for Mac BTW

Error from Spring Boot:

Caused by: java.net.ConnectException: Connection refused

If I start the mysql with docker compose without the spring boot app in the compose file, and just use a run command with a link to the running mysql container started with docker compose, it works with this jdbc connection string

url: jdbc:mysql://icentiadb/icentia?autoReconnect=true&useSSL=false

Any help appreciated thanks

Author:Ali Dufour,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/38482062/docker-compose-mysql-link-issue-with-spring-boot
yy