user7024438
user7024438

Reputation:

Spring boot app not able to connect to mysql database running in docker container while running as a container

server.port = 8080
spring.datasource.url= jdbc:mysql://192.168.99.100:3307/user_info
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.dialect.storage_engine=innodb
spring.jpa.database-platform: org.hibernate.dialect.MySQL5InnoDBDialect


#eureka.client.service-url.default.zone = http://localhost:8761/eureka
#eureka.client.register-with-eureka=false
#eureka.client.fetch-registry=false
#eureka.instance.hostname=localhost

Docker

I have created a container for spring boot app using docker and same for mysql but sboot app is not able to connect to mysql but when i try to run on local it gets connected easily, I have put my application.properties file please tell what should be done to fix the issue The docker is running on 192.168.99.100

Upvotes: 0

Views: 333

Answers (2)

user7024438
user7024438

Reputation:

Actually the issue was that i was deploying a old jar on docker, I recreated the jar and deployed and everything worked fine.

Upvotes: 0

Giga Kokaia
Giga Kokaia

Reputation: 929

Use your hosts ip with published port 3307. If you are using internal ip address, use private port 3306

spring.datasource.url= jdbc:mysql://192.168.99.100:3306/user_info

but better to use with hostname

spring.datasource.url= jdbc:mysql://mysql-dev:3306/user_info

Upvotes: 2

Related Questions