I have an java spring / hibernate application and I cant create a connection beween the mysql and java containers. When I start just the mysql Container and run the java application manualy in CMD it works fine. But once the java application runs in a container I get the following problem:
bookAPI | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
bookAPI |
bookAPI | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
bookAPI | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
bookAPI | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
If I understand the error correctly the java container can send to the mysql container but not the other way around. I have linked the java container to the mysql container. Anyone knows how to connect these containers correctly?
My docker-compose.yml looks like this:
version: '3'
services:
db:
image: mysql:5.7
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: aaaaaa
MYSQL_DATABASE: bookAPI
MYSQL_USER: aaaaaa
MYSQL_PASSWORD: aaaaaa
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8081:80
java:
container_name: bookAPI
image: openjdk:8
depends_on:
- db
volumes:
- ./:/app
working_dir: /app
command: bash -c "cd /app && java -jar bookAPI.jar"
stdin_open: true
tty: true
ports:
- 8080:8080
links:
- db
links:then the setup described in Networking in Compose should work just fine. What address are you trying to connect to? Can you show that part of your configuration?