How to connect MySQL docker container with spring boot app image for production ?
See original GitHub issueHi! I want to run the same spring boot app on my laptop at the time of development with connecting my own installed MySQL and in production with MySQL docker container. I tried more but getting the issue with JDBC connection exception. Please help me.
I am using two files same project for that.
# application.properties for local MySQL connection
spring.datasource.platform=mysql
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url= jdbc:mysql://localhost:3306/tsbacked?useSSL=false
spring.datasource.username = root
spring.datasource.password = 12345
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
# application.yml for Docker container MySQL
spring:
jpa:
database: MYSQL
hibernate:
ddl-auto: validate
datasource:
url: jdbc:mysql://mysql:3306/tsbacked
username: root
password: 12345
driver-class-name: com.mysql.jdbc.Driver
# Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD target/techlaviya-0.0.1.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
docker run --name demo-mysql -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=tsbackedMYSQL_USER=root-e MYSQL_PASSWORD=12345 -d mysql:5.6
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Deploy Spring Boot + MYSQL Application to Docker - JavaInUse
In this post we will deploy Spring Boot + MYSQL application to docker. We will see how this is achieved using both with...
Read more >How to connect a MySQL Docker Container to a Spring Boot ...
Run your Spring Boot application. Then, head to your Adminer interface, click on the refresh button and you should see your new database...
Read more >Spring Boot + MySQL docker containers - Stack Overflow
When I run the Spring app on my local machine, it successfully connects to my MySQL db running in a docker container. Once...
Read more >Docker Compose: Spring Boot and MySQL example - BezKoder
Create Dockerfile for Spring Boot App · FROM : install the image of the Maven – JDK version. · WORKDIR : path of...
Read more >Dockerizing a Spring Boot + MySQL Application
Photo by Dominik Lückmann on Unsplash · Docker build · Images · Network · Run MySQL container · MySQL logs · Run Spring-boot...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ohhh I found the solution. You can read this tutorial: https://g00glen00b.be/docker-spring-boot/. The problem is your application load the application.properties. You need to change the ENTRYPOINT to load the profile with the container configuration (application.yml). E.g “-Dspring.profiles.active=container”
Running with a database is out of scope for this guide. If you want to see some guidance, maybe open an issue in the extended topical guide.