1

I am working on Windows 10 Environment. My Docker version 1.13.0, build 49bf474.

I have a Spring Boot application running on Docker container I am trying to access local instance of MySQL from Spring Application. My instance of MYSQL is not running on container.

I understand this is a networking issue and already try to run docker using following command : docker run -p 8282:8191 ami --network="host" but no success.

Can somebody please help me to resolve this issue.

Thanks in advance.

Note : My Spring application configuration is fine as i am able to connect AWS MSQL RDS server from container without any issue.

The error I am receiving as below

2019-04-19 07:33:32.025  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3308 ms
2019-04-19 07:33:32.264  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-04-19 07:33:33.422 ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Few Information :

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/financedb
spring.datasource.username=****
spring.datasource.password=****
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

1 Answer 1

3

Docker for Windows uses a vm to run Linux containers. The “localhost” is therefore the vm and not your windows machine when running with net=host You can use the special host name as MySQL host

docker.for.win.localhost

This points to your windows machine and you can even run without net=host.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your response. Could you please give me some reference or some guidance how to map special host name in docker ..please
The special host name is provided by Docker on windows / Mac automatically.
Thanks Thomas. it helps me .. Only change i have to do ..to up-grade my docker version. Thanks again .. It is working now ..
spring.datasource.url=jdbc:mysql://docker.for.win.localhost:3306/financedb
Any idea about how to use this in Linux? we used localhost, but it was not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.