【发布时间】:2019-01-02 07:11:23
【问题描述】:
我使用 springboot 数据和 postgres 创建了一个示例 java 项目。我开始制作我的 docker-compose,但我无法将我的数据库链接到我的应用程序...
我有这个错误
web_1 | org.postgresql.util.PSQLException: Connection to localhost:5438 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
在我的应用程序资源上
server:
port: 4000
spring:
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5438/acronym
username: acronym
password: acronym1234
driver-class-name: org.postgresql.Driver
jpa:
database: POSTGRESQL
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: create
和我的 docker 撰写文件
version: '3.3'
services:
web:
image: acronym:latest
ports:
- 4000:4000
networks:
- webnet
depends_on:
- db
db:
image: postgres:9.6
restart: always
environment:
- POSTGRES_USER=acronym
- POSTGRES_PASSWORD=acronym1234
- POSTGRES_DB=acronym
-PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- /var/lib/postgresql/data
ports:
- '5438:5432'
volumes:
db:
networks:
webnet:
看了很多话题,解决办法是把localhost换成db,但是不行
如何使用 docker-compose 将我的数据库链接到我的应用程序?
【问题讨论】:
标签: java postgresql docker