简体   繁体   English

Docker-组成up springboot + postgres连接被拒绝

[英]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.

相关问题 可怕的 Java SpringBoot 应用程序未通过 Docker-compose java.net.ConnectException 连接到 MySQL:连接被拒绝 - The dreaded Java SpringBoot app not connecting to MySQL with Docker-compose java.net.ConnectException: Connection refused 如何在docker-compose中修复Jedis中的拒绝连接错误? - How to fix connection refused error in Jedis in docker-compose? Spring Boot + docker-compose + MySQL:连接被拒绝 - Spring Boot + docker-compose + MySQL: Connection refused 将 Spring 引导和 redis 与 docker-compose 组合:连接被拒绝 - Combining Spring boot and redis with docker-compose: Connection refused 为什么在通过 docker-compose 启动 rabbit 时出现连接拒绝错误? - Why I have a connection refused error when starting rabbit by docker-compose? 使用docker-compose启动dockerized Spring Boot和MariaDb时出现连接拒绝错误 - Connection refused error when starting dockerized Spring Boot and MariaDb with docker-compose Postgres docker-compose 使用测试容器不起作用 - Postgres docker-compose using testcontainers not working (Docker+SpringBoot+Mysql) Mysql 连接被拒绝 - (Docker+SpringBoot+Mysql) Mysql connection refused Docker 运行 - MySQL Springboot 连接被拒绝 - Docker run - MySQL Springboot Connection refused docker-compose java应用程序连接到mongodb - docker-compose java application connection to mongodb
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM