Reputation: 161
When my java spring application tries to connect to the database I get the following:
Caused by: 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.
The connection url in the spring application is as follows:
jdbc:mysql://mysqldbserver:3306/supersede_orchestrator_spring?useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
where mysqldbserver is the service name from the docker-compose config:
version : '3'
services:
springappserver:
build:
context: .
dockerfile: web.dockerfile
ports:
- "8081:8080"
networks:
- mt-network
volumes:
- .:/vol/development
depends_on:
- mysqldbserver
mysqldbserver:
build:
context: .
dockerfile: db.dockerfile
ports:
- "13306:3306"
networks:
- mt-network
environment:
MYSQL_DATABASE: supersede_orchestrator_spring
MYSQL_USER: supersede_orch
MYSQL_PASSWORD: ****
MYSQL_ROOT_PASSWORD: ****
container_name: orchestrator_mysqldbserver
networks:
mt-network:
driver: bridge
In the mysql docker container I already adjusted the bind-address to 0.0.0.0. The privileges of the supersede_orch user are set to %. When I connect to the springappserver docker container, I can reach the database via telnet mysqldbserver 3306 and I can also connect to the database on the command line from the spring docker container: mysql -h mysqldbserver -u supersede_orch -p. Though the java spring application fails to connect to the DB running on the other docker container.
The web.dockerfile looks as follows:
FROM java:8-jre
VOLUME /tmp
ADD build/libs/feedback_orchestrator-2.0.0.jar app.jar
RUN apt-get update
RUN apt-get install mysql-client -y
RUN apt-get install libmysql-java -y
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom -Djava.net.preferIPv4Stack=true","-jar","/app.jar"]
So, I tried to make sure that java uses IP4 to resolve mysqldbserver (I also used the corresponding IP address for mysqldbserver which also failed).
Finally docker images -a:
42db4e656e6e orchestrator_springappserver "java '-Djava.secu..." 16 minutes ago Up 16 minutes 0.0.0.0:8081->8080/tcp orchestrator_springappserver_1
e2b0b5cc15ac orchestrator_mysqldbserver "docker-entrypoint..." 2 hours ago Up About an hour 0.0.0.0:13306->3306/tcp orchestrator_mysqldbserver
Do you have any idea what the problem could be? Thank you!
Upvotes: 10
Views: 17774
Reputation: 115
I got this error. For me I forgot to start up WAMP, which has the mysql info.
Upvotes: -1
Reputation: 161
The above configuration is correct. I was just stupid enough to forget rebuilding the jar. So, the jdbc url was not updated. It works now perfectly.
Upvotes: 5