docker compose: spring boot connection to mysql database refused

Japhet

I'm pretty new to Docker and I need to startup my Angular/SpringBoot/MySQL project with docker-compose on the docker toolbox. I copied a docker yml file into my project which used the same technologies and changed the paths inside of it to match my project. However when I try docker-compose, it throws the following error:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
[...] 84 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)

the docker-compose.yml looks like:

version: '3'

services:
  database:
    image: mysql
    container_name: database
    environment:
      MYSQL_ROOT_PASSWORD: ****
      MYSQL_DATABASE: db_example
      MYSQL_USER: springuser
      MYSQL_PASSWORD: ****
    ports:
      - 3306:3306
    volumes:
      - db_exampleData:/var/lib/mysql

  springapi:
    image: openjdk:10-jre-slim
    container_name: springapi
    ports:
      - 8443:8443
    depends_on:
      - database
    volumes:
      - ./backend/target/backend-0.1.0.jar:/application.jar
    command: ["java", "-jar", "application.jar"]

  angular:
    image: nginx:alpine
    container_name: angular
    ports:
      - 4200:80
    depends_on:
      - springapi
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./frontend/my-app/dist/my-app:/usr/share/nginx/html

volumes:
  db_exampleData:

the application.properties:

spring.jpa.hibernate.ddl-auto=none
spring.jpa.open-in-view=false
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=springuser
spring.datasource.password=****

server.port=8443

any suggestion would be helpful!

LinPy

you need to change your connecion like this:

jdbc:mysql://database:3306/db_example

and add this to your docker-compose under springapi service:

links:
   - database

on the other hand you may use wait-for-it.sh to check if DB is up by add a command section under springapi service:

command: ["path/to/wait-for-it.sh", "database:3306", "-t", "6000", "--", "YOUR ACTUAL COMMAND"]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Docker compose Redis and Spring boot app: java.net.ConnectException: Connection refused (Connection refused)",

docker-compose wordpress mysql connection refused

docker compose MySQL container [2002] Connection refused

spring boot eureka with docker gets connection refused

Spring boot + docker + rest template connection refused

Docker Compose & Postgres Connection Refused

Connection Refused when initializing Hibernate with MySQL in docker-compose

Docker compose spring boot redis connection issue

Docker Compose + Spring Boot + Postgres connection

Docker Compose with Two Spring Boot Application get "message": "I/O error on GET request for \"http://127.0.0.1:8010/....: Connection refused"

Docker, Mongodb,Spring Boot on Windows getting Connection refused error

Connection refused by Spring boot app running in different docker container

Spring Boot, PostgreSQL, and Docker - Connection Refused whil Running in Container

Connection refused error between react and spring boot in a docker environment

Spring boot inside docker container throws java.net.ConnectException: Connection refused (Connection refused)

Connecting PostgreSQL database to Spring application (both running in docker) Connection refused

Spring Boot - webservice: Connection Refused

Connection refused on Docker Mysql with Laravel

Golang MySQL Docker connection refused

Docker MYSQL '[2002] Connection refused'

Docker PHP MySQL connection refused

Elixir + docker compose Connection with postgres refused

docker-compose: mariadb - Connection refused

Docker Compose - container receiving connection refused

Docker-compose Postgres connection refused

Docker (compose): connection refused without sudo

ScrapydWeb: Connection refused within docker-compose

docker-compose connection refused 5432

Spring Boot connection to MySQL remote database

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive