question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to connect MySQL docker container with spring boot app image for production ?

See original GitHub issue

Hi! 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:closed
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
nbentonevescommented, Dec 12, 2017

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”

spring:
    profiles: container
    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
0reactions
dsyercommented, Jan 6, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found