I have installed docker on Windows machine using docker tool box. I also have mysql installed on my windows machine and the server is running on port 3306 (localhost - 127.0.0.1 - outside the docker machine) I am running a sprint boot application inside a docker container with name as 'micra-workq-svc' inside the docker network called 'micra-network' I want application running inside the docker to connect to this local host. I spent hours searching on google and none of the links help me to resolve this issue. I tried running mysql image with this command:
docker run --name micra-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=<pass> -e MYSQL_DATABASE=<db name> -e MYSQL_USER=<roo user> -e MYSQL_PASSWORD=<root password >--net=micra-network mysql:latest
I am using following command to run my container:
docker run -e "SPRING_PROFILES_ACTIVE=dev" --network micra-network --env "eureka.client.enabled=true" --env "eureka.host=micra-eureka-server" --env "eureka.instance.preferIpAddress: true" --env "eureka.client.serviceUrl.defaultZone=http://micra-eureka-server:8761/eureka" --env DATABASE_HOST=127.0.0.1 --env DATABASE_PORT=3306 --env DATABASE_NAME=<db name> --env DATABASE_USER=<db user> --env DATABASE_PASSWORD=<db password> --expose 8083 -p 8083:8083 --name micra-workq-svc --link micra-mysql -t <my docker service image>
This is how application.properties look like in spring boot:
spring:
datasource:
password: ${DATABASE_PASSWORD}
url: jdbc:mysql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
username: ${DATABASE_USER}
When I run my service I get following error:
Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.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.
My docker machine ip is 192.168.99.100.