java.net.unkownhost_Docker撰写(v2)UnkownHostException

当使用Docker Compose并尝试将spring引导Web应用程序容器与mysql容器链接时,我收到“java.net.UnkownHostException:mysql:unknown error” .

docker-compose.yml 更新#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 更新#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)

更新#2 Nguyen Sy Thanh Son建议的方法是正确的 . 我的解决方案使用public wait-for-it.sh脚本 . 在这里查看我的解决方案:https://github.com/thomptr/DockerDemo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值