I'm getting a "java.net.UnkownHostException: mysql: unknown error" when using Docker Compose and trying to link a spring boot web application container with a mysql container.
docker-compose.yml update #1
version: '2'
services:
web:
depends_on:
- db
image: thomptr/rest-services-ui:latest
ports:
- "9000:9000"
links:
- "db:database"
restart: always
environment:
SPRING_PROFILES_ACTIVE: dev
envTarget: dev
db:
image: mysql:5.7
ports:
- "3307:3306"
volumes:
- "/home/trevor/softwareDev/mySql/dump:/docker-entrypoint-initdb.d"
environment:
MYSQL_ROOT_PASSWORD: legion03
MYSQL_DATABASE: dev
MYSQL_USER: dbuser
MYSQL_PASSWORD: legion03
application-dev.properties update #1
spring.profiles.active=dev
server.contextPath=/restservices
server.port: 9000
spring.datasource.initialize=false
spring.datasource.platform=mysql
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://database:3306/dev
spring.datasource.username=dbuser
spring.datasource.password=legion03;
hibernate.level.logging=debug
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database=mysql
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
logs from /dockercompose_web_1 container
2016-07-01 04:17:24.119 ERROR 1 --- [ost-startStop-1] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
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.
Caused by: java.net.UnknownHostException: mysql: unknown error
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
UPDATE #2 The approach suggested by Nguyen Sy Thanh Son is correct. My solution uses the public wait-for-it.sh script. See my solution here : https://github.com/thomptr/DockerDemo