I'm new on Springboot and docker.
I'm trying to create three different microservices and load them into docker.
Two of them start correctly while the last one returns the following error:
Caused by: com.mysql.cj.exceptions.CJException: Access denied for user 'db_user'#'%' to database 'PaymentDB'
I can't find the error. The configuration of the three microservices are exactly the same (sometimes I copied and paste the similar code and changed only the name for example from Catalog to Payment. Can You suggest me something?
This is the application.properties:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${PM_DATASOURCE_HOST}:${DATASOURCE_PORT}/${PM_DATASOURCE_NAME}?autoReconnect=true
spring.datasource.username=${DATASOURCE_USER}
spring.datasource.password=${DATASOURCE_PASSWORD}
spring.kafka.bootstrap-servers=kafka:9092
kafkaTopic=payment-topic
This is the .env :
DB_DATABASE_PAYMENT=PaymentDB
DB_HOST_PAYMENT=paymentmysqldb
DB_DATABASE_USER=UserDB
DB_HOST_USER=usermysqldb
DB_DATABASE_CATALOG=CatalogDB
DB_HOST_CATALOG=catalogmysqldb
DB_USER=db_user
DB_PASSWORD=alx2022
DB_ROOT_PASSWORD=user
DB_PORT=3306
This is the docker-compose.yml
version: '3.4'
x-common-variables: &common-variables
DATASOURCE_USER: ${DB_USER}
DATASOURCE_PASSWORD: ${DB_PASSWORD}
DATASOURCE_PORT: ${DB_PORT}
services:
paymentmysqldb:
container_name: paymentmysqldb
image: mysql
ports:
- "3313:3306"
environment:
- MYSQL_DATABASE=${DB_DATABASE_PAYMENT}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- paymentstorage:/var/lib/mysql
usermysqldb:
container_name: usermysqldb
image: mysql
ports:
- "3311:3306"
environment:
- MYSQL_DATABASE=${DB_DATABASE_USER}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- userstorage:/var/lib/mysql
catalogmysqldb:
container_name: catalogmysqldb
image: mysql
ports:
- "3312:3306"
environment:
- MYSQL_DATABASE=${DB_DATABASE_CATALOG}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- catalogstorage:/var/lib/mysql
paymentmanager:
container_name: paymentmanager
image: arausa/paymentimage
build:
context: .
dockerfile: MicroServices/PaymentManager/Dockerfile
depends_on:
- paymentmysqldb
ports:
- "3333:8080"
restart: always
environment:
<<: *common-variables
PM_DATASOURCE_HOST: ${DB_HOST_PAYMENT}
PM_DATASOURCE_NAME: ${DB_DATABASE_PAYMENT}
usermanager:
container_name: usermanager
image: arausa/userimage
build:
context: .
dockerfile: MicroServices/UserManager/Dockerfile
depends_on:
- usermysqldb
ports:
- "1111:8080"
restart: always
environment:
<<: *common-variables
UM_DATASOURCE_HOST: ${DB_HOST_USER}
UM_DATASOURCE_NAME: ${DB_DATABASE_USER}
catalogmanager:
container_name: catalogmanager
image: arausa/catalogimage
build:
context: .
dockerfile: MicroServices/CatalogManager/Dockerfile
depends_on:
- catalogmysqldb
ports:
- "2222:8080"
restart: always
environment:
<<: *common-variables
CM_DATASOURCE_HOST: ${DB_HOST_CATALOG}
CM_DATASOURCE_NAME: ${DB_DATABASE_CATALOG}
#kafka usa zookeeper tiene traccia dei broker, topologia della network e info per la sincronizzazione
zookeeper:
image: wurstmeister/zookeeper
#identifica il broker kafka
kafka:
image: wurstmeister/kafka
ports:
- "9092:9092" #porta di default per il broker kafka
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 #serve a dire dove sta girando zookeeper
volumes:
userstorage:
catalogstorage:
paymentstorage:
This is the pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>PaymentManager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PaymentManager</name>
<description>PaymentManager</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is the docker file :
FROM maven:3-openjdk-17-slim as builder
WORKDIR /project
COPY MicroServices/PaymentManager/ .
RUN mvn package
FROM openjdk:17-alpine
WORKDIR /app
COPY --from=builder /project/target/PaymentManager-0.0.1-SNAPSHOT.jar ./PaymentManager.jar
CMD java -jar PaymentManager.jar
Seems like your application.properties has some error.
spring.datasource.username=${DATASOURCE_USER}
spring.datasource.password=${DATASOURCE_PASSWORD}
these env variables aren't defined or exported from anywhere.
I solved in a strange way.
I modified the word "Payment" with the word "pay" everywhere and it magically works. Even if I don't understand the reason
Related
I have created a simple spring boot app to communicate with MYSQL via Docker using the same network. Once I run docker-compose up command then following errors have occurred.
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up
(https://i.stack.imgur.com/gwUuG.png)
version: "3.8"
services:
project:
build: .
ports:
- "8080:8080"
environment:
-SPRING_DATASOURCE_URL: jdbc:mysql://mysqldb:3306/spring?autoReconnect=true&useSSL=false
depends_on:
- mysqldb
mysqldb:
image: mysql:8
ports:
- 33066:3306
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_DATABASE=spring
volumes:
- spring:/data/db
volumes:
spring:
here is my yaml file
spring.datasource.url=jdbc:mysql://localhost:3306/spring?
serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=1234
spring.jpa.database=mysql
server.error.include-message=always
server.error.include-binding-errors=always
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = create
here is my app properties file
I tried recreating over and over again, prune all the files(network image container) in Docker. Tried creating network via Terminal.
it would be more helpful if you add your pom.xml or gradle configs and your application.yml. However, make sure to have the following:
The correct dependency with a compatible version:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
In your application.properties
server.port=8080
spring.datasource.url=jdbc:mysql://<host>:3306/<dbname>
spring.datasource.username=<username>
spring.datasource.password=<password>
host will be localhost if you are running your application locally, if your spring boot is in a container in your case it should be as you mentioned mysqldb. You also need to make sure that your database schema is already created
Your docker-compose.yml
version: '3' # specify a version
services:
mysqldb: # container-name
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=<password>
- MYSQL_DATABASE=<dbname>
- MYSQL_USER=<user-name>
- MYSQL_PASSWORD=<password>
volumes:
- app-data:/var/lib/mysql
spring-boot:
ports:
[8080:8080]
build:
context: ./
dockerfile: Dockerfile
depends_on:
- mysqldb
volumes:
app-data:
In my production environment with this command I run my docker-compose:
docker-compose -f docker-compose.yml up -d
DOCKER-COMPOSE
version: "3.3"
services:
db:
image: mysql
platform: linux/amd64
restart: always
container_name: mysql-db-users
environment:
MYSQL_ROOT_PASSWORD: 'password'
MYSQL_DATABASE: 'userDb'
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin
restart: always
container_name: php-my-admin-users
ports:
- "8081:80"
Now by connecting to 172.22.14.43:8081 I can login to phpmyadmin when I can find that userDb has been created.
The next step is to connect a dockerized Springboot app to this userDb, but I continue to obtain:
com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
This is the dockerfile of my SprigBoot App:
DOCKERFILE
FROM openjdk:17-jdk
ARG JAR_FILE=target/*.jar
COPY target/ldap-conn-*.jar /ldap-conn.jar
ENTRYPOINT ["java", "-jar", "/ldap-conn.jar" ]
EXPOSE 8090
APPLICATION.YML
server:
port: '8090'
spring:
application:
name: ldap-connection
datasource:
username: 'root'
password: 'password'
platform: 'mysql'
url: jdbc:mysql://mysql-db-users:3006/userDb?useSSL=false&allowPublicKeyRetrieval=true
sql:
init:
mode: always
jpa:
defer-datasource-initialization: 'true'
hibernate:
ddl-auto: update
properties:
hibernate:
data: classpath:Data.sql
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
format_sql: true
show-sql: true
eureka:
client:
service-url:
defaultZone: http://172.17.0.2:8761/eureka
fetch-registry: true
register-with-eureka: true
And in my POM.XML I have both these dependencies:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
I run my image in this way:
docker run -d -p 8090:8090 --name ldap myRepo/ldap1.0:ldap
I think the main issue is this line:
url: jdbc:mysql://mysql-db-users:3006/userDb?useSSL=false&allowPublicKeyRetrieval=true
As far as I understand using the container name is the way to go, but it doesn't seem to work.
I've tried by using the ip address of the docker container (with Eureka server is working)
jdbc:mysql://172.17.0.2:3006/userDb
the server ip
jdbc:mysql://serverIp:3006/userDb
but this is not working.
I'm trying to set up GitHub Actions for building a maven project with Coveralls on a public repository. For some reason it keeps failing with this error:
Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:4.3.0:report (default-cli) on project e-shop-manager: Build error: Either repository token or service with job id must be defined -> [Help 1]
I have looked through the coveralls documentation (both plugin and actions-side) to no avail.
Here is the yaml from Actions:
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: Set up JDK 11
uses: actions/setup-java#v3
with:
distribution: 'adopt'
java-version: '11'
cache: 'maven'
- name: Build with Maven
run: mvn clean package jacoco:report coveralls:report
- name: Coveralls
uses: coverallsapp/github-action#master
with:
github-token: ${{ secrets.COVERALLS_TOKEN }}
where COVERALLS_TOKEN is my secret token, 100% sure it's been added as a repository secret.
Here is my maven project configuration too:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.unipd.mtss</groupId>
<artifactId>e-shop-manager</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>e-shop-manager</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<failsOnError>true</failsOnError>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
</plugin>
</plugins>
</build>
</project>
I couldn't find anything elsewhere other than documentation, since I have pretty much copied configs from docs.
I am working on Windows, Docker Desktop version 19.03.1, build 74b1e89 and docker-compose version 1.24.1, build 4667896b
My docker machine is hyper-v
I am trying to initialize the mysql database docker container for the deploy of my spring jpa app.
I have a docker-compose.yml file with two services: mysql-docker-container and spring-jpa-app. This file is in /resources/ folder inside project.
The init.sql file is located there too.
I am locating the init.sql in the same folder as application.properties because I read that with this configuration:
spring.datasource.initialization-mode=always
spring.datasource.type=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
spring.jpa.hibernate.ddl-auto=none
and excluding HikariCP:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</exclusion>
</exclusions>
</dependency>
it would load all database and data in init.sql
But instead, I get Communications link failure but still starts the application.
Postman works and gives respones but without the data that i want to load, results empty.
That is why I included the healthcheck to check if mysql container is "healthy" but I am not sure that is what I need.
Also, I tried to enter the mysql container (when app started after docker-compose up --build) in another git bash as administrator but I cannot access to it because docker ps -a is empty
docker-compose-yml
version: '3.7'
services:
mysql-docker-container:
image: mysql
networks:
- mired
container_name: mysql-docker-container
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=database
- MYSQL_USER=user
- MYSQL_PASSWORD=user
ports:
- 2012:3306
volumes:
- c:/Users/User/Documents/project/src/main/resources/db/:/docker-entrypoint-initdb.d
tty: true
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping']
interval: 10s
timeout: 2s
retries: 10
spring-jpa-app:
build:
context: .
dockerfile: Dockerfile
networks:
- mired
container_name: spring-jpa-app
links:
- mysql-docker-container:mysql-docker-container
depends_on:
- mysql-docker-container
ports:
- 8087:8080
tty: true
networks:
mired:
Dockerfile
FROM java:8
VOLUME /tmp
EXPOSE 8080
ADD app.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
application.properties
server.port=8080
spring.datasource.url=jdbc:mysql://172.18.67.41:3306/database?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&autoReconnect=true&useSSL=false
spring.datasource.username=user
spring.datasource.password=user
spring.datasource.initialization-mode=always
spring.datasource.type=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
spring.jpa.hibernate.ddl-auto=none
logging.file=log/log.log
logging.level.org.springframework=info
logging.level.orghibernate=info
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.app</groupId>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<name>app</name>
<description>Application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0-spring-security-api</artifactId>
<version>1.0.0-rc.3</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
spring-jpa-app | 2019-08-05 10:23:44.920 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
spring-jpa-app |
spring-jpa-app | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
spring-jpa-app |
spring-jpa-app | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
I have 3 dockerfiles for WSO2 apim, identity server, and mysql. using docker-compose to run these. The corresponding docker-compose.yml is given as below:-
# docker-compose version
version: "3.7"
# services/containers to be run
services:
wso2am:
build: ./apim
image: wso2am:2.6.0
ports:
- "9443:9443"
links:
- mysql-db
- wso2is-km
wso2is-km:
build: ./is-as-km
image: wso2is-km:5.7.0
ports:
- "9444:9444"
links:
- mysql-db
mysql-db:
build: ./mysql
image: mysql:5.7.26
ports:
- "3306:3306"
- "33060:33060"
When running without changing h2 database to mysql Identity server/ apim works fine at ports 9444/9443 respectively. Also in mysql docker created regdb/apidb sql databases from the datascripts folder in apim/identity server.
# Derived from official mysql image (our base image)
FROM mysql:5.7
MAINTAINER Abhilash K R <abhilash.kr#aot-technologies.com>
ENV MYSQL_ROOT_PASSWORD root
# Add a user
ENV MYSQL_USER wso2carbon
ENV MYSQL_PASSWORD wso2carbon
# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
COPY sql-scripts/ /docker-entrypoint-initdb.d
# expose ports
EXPOSE 3306 33060
Added jdbc driver and added new db url as below:
<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/regdb</url>
<username>wso2carbon</username>
<password>wso2carbon</password>
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
<defaultAutoCommit>true</defaultAutoCommit>
</configuration>
</definition>
</datasource>
Getting the error as below:
Thinking the error is at the url jdbc:mysql://localhost:3306/regdb , tried to give localhost/ip of the dockerhost also still didn0t work.
Try to change the mysql connection string as below -
<url>jdbc:mysql:jdbc:mysql://mysql-db:3306/regdb</url>
In compose, services are reachable by their name itself. No need to use links etc. You can use depends_on or service_healthy in case you have interdependent services.
Ref - https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on
This is due to the error when connecting to user database. Could you verify whether the username and password configured for this database is correct?