2

I have an springboot java app inside docker that needs to access an external mysql.

How can I configure this? Is it possible to define it inside Dockerfile?

I am now to docker so I assume this should be a simple and common task :)

When I run the app I receive the error

2019-02-12 15:10:51,472 DEBUG [main] com.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Cannot acquire connection from data source java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

my Dockerfile

FROM openjdk:11.0.2-jre-slim VOLUME /tmp COPY target/app-0.4-SNAPSHOT.jar app.jar ENTRYPOINT ["java","-jar","/app.jar"] EXPOSE 9001/tcp 
2
  • Where is this external mysql server? Commented Feb 12, 2019 at 16:26
  • of course..I don't know why I haven't think of that @v25 can you answer I will accept it Commented Feb 12, 2019 at 23:15

1 Answer 1

1

If the mysql server is running on the docker host, either on metal or in another contianer with a mapped port, it could be that your app's configuration is still looking for the database server on localhost which within its container points to the loopback interface INSIDE the container.

You can get around this with the special address: host.docker.internal see info

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.