我试图通过教程学习spring boot,但我似乎无法连接到docker中的postgresql数据库。与本地数据库配合使用非常好。
我的docker-compose.yml:
services:
db:
image: postgres
ports:
- "5432:5432"
restart: always
environment:
POSTGRES_PASSWORD: admin
POSTGRES_USER: postgres
我的application.properties:
spring.datasource.url=jdbc:postgresql://db:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=admin
spring.datasource.driver-class-name=org.postgresql.Driver
我没有连接,而是不断收到以下错误:
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
我的docker日志没有显示任何登录尝试。