[英]Docker-compose up springboot + postgres Connection refused
I create an sample java project with springboot data and postgres. 我用springboot数据和postgres创建一个示例Java项目。 I started to make my docker-compose but i can't link my database to my application...
我开始做我的docker-compose,但是我无法将数据库链接到我的应用程序...
I have this error 我有这个错误
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.
On my application ressource 在我的应用程序资源上
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
and my docker compose file 和我的码头工人撰写文件
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:
I saw a lot of topic and the solution is to replace localhost to db but that doesn't work 我看到了很多话题,解决方案是将localhost替换为db,但这不起作用
How can i link my database to my app with docker-compose ? 如何使用docker-compose将数据库链接到我的应用程序?
Use jdbc:postgresql://db:5438/acronym
as connection url. 使用
jdbc:postgresql://db:5438/acronym
作为连接URL。
The service is exposed under its name by default (in that case db
). 默认情况下,该服务以其名称公开(在这种情况下为
db
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.