I have two Spring apps that shares the same Mysql database. They work perfectly when I run them without docker-compose. My host machine is Windows 10 professional.
application.properties
server.port=8085
spring.jpa.show-sql=true
spring.jackson.serialization.write-dates-as-timestamps=false
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306 /webDatabase?autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=my-secret-pw
Dockerfile
FROM openjdk:8-jdk-alpine
ADD target/web-spring-boot.jar web-spring-boot.jar
EXPOSE 8085
ENTRYPOINT ["java","-jar", "web-spring-boot.jar"]
I created this docker-compose.yml based on other examples.
version: '3'
services:
web:
build: ./web
ports:
- "8085:8085"
depends_on:
- "database"
solver:
build: ./solver
ports:
- "8095:8095"
depends_on:
- "database"
database:
image: "mysql:latest"
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=my-secret-pw
- MYSQL_DATABASE=webDatabase
healthcheck:
test: "/usr/bin/mysql --user=root --password=my-secret-pw --execute \"SHOW DATABASES;\""
interval: 10s
timeout: 20s
retries: 10
volumes:
logvolume01: {}
It doesn´t work. After startup only the Mysql container is running.
Here is part of the output with Spring logs
solver_1 | 2019-01-04 22:55:15.698 WARN 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08S01 solver_1 | 2019-01-04 22:55:15.698 ERROR 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Communications link failure solver_1 | solver_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
What am I missing in the configuration? Does application.properties
are ignored when running with composing?