简体   繁体   English

PostgreSQL + 元数据库连接被拒绝

[英]PostgreSQL + metabase connection refused

I am trying to configure postgres to run with springboot and metabase.我正在尝试将 postgres 配置为与 springboot 和元数据库一起运行。 Each service is running separately alone but when I try to put the 3 together in a docker-compose file, I am getting the following error :每个服务都单独运行,但是当我尝试将这 3 个服务放在 docker-compose 文件中时,出现以下错误:

 Caused by: org.postgresql.util.PSQLException: Connection to 0.0.0.0:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
metabase-container |    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:303)

However, I have mapped the port 5432 of db to the port 5432 of the metabase container.但是,我已经将db的5432端口映射到元数据库容器的5432端口。

And yet, It doesn't seem to work.然而,它似乎不起作用。 Any help on this issue?对这个问题有什么帮助吗? (please find my docker-compose file below) (请在下面找到我的 docker-compose 文件)

version: '2'

services:
  spring:
    image: 'realtime:latest'
    container_name: spring
    depends_on:
      - db
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
      - SPRING_DATASOURCE_USERNAME=compose-postgres
      - SPRING_DATASOURCE_PASSWORD=same
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update
    volumes:
      - /home/vagrant/valorisation-2.0:/app
    command: ["java", "-jar", "rtv-1.jar"] 
    mem_limit: 10g
    mem_reservation: 10g
    ports:
      - "8079:8080"
  db:
    image: 'postgres:13.1-alpine'
    container_name: db
    environment:
      - POSTGRES_USER=compose-postgres
      - POSTGRES_PASSWORD=********
      - METABASE_PASSWORD=same
    ports:
      - "8078:5432"
      - "54320:5432"
  metabase:
    container_name: metabase-container
    restart: "always"
    image: metabase/metabase
    ports:
      - "3000:3000"
      - "5432:5432"
    environment:
      - MB_DB_TYPE=postgres
      - MB_DB_DBNAME=db
      - MB_DB_PORT=5432
      - MB_DB_USER=compose-postgres
      - MB_DB_PASS=same
      - MB_DB_HOST=0.0.0.0
      - MB_ENCRYPTION_SECRET_KEY=********

尝试将元数据库环境变量中的MB_DB_HOST0.0.0.0更改为db

The subtilty I hadn't understood is that all the services are in the same network.我没有理解的微妙之处在于所有服务都在同一个网络中。 Hence, deleting port forwarding (which exposes the services to outside components but is irrelevant for communication within the container) between the services and changing the Metabase configuration file does the job.因此,删除服务之间的端口转发(将服务暴露给外部组件但与容器内的通信无关)并更改元数据库配置文件即可完成这项工作。 Here is the modified docker-compose.yml file :这是修改后的 docker-compose.yml 文件:

version: '2'

services:
  spring:
    image: 'realtime:latest'
    container_name: spring
    depends_on:
      - db
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
      - SPRING_DATASOURCE_USERNAME=********
      - SPRING_DATASOURCE_PASSWORD=**********
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update
    volumes:
      - /home/vagrant/valorisation-2.0:/app
    command: ["java", "-jar", "rtv-1.jar"] 
    mem_limit: 10g
    mem_reservation: 10g
    ports:
      - "8079:8080"
  db:
    image: 'postgres:13.1-alpine'
    container_name: db
    environment:
      - POSTGRES_USER=compose-postgres
      - POSTGRES_PASSWORD=compose-postgres
      - METABASE_PASSWORD=compose-postgres
    ports:
      - "8078:5432"
  metabase:
    container_name: metabase-container
    depends_on:
      - db
    restart: "always"
    image: metabase/metabase
    ports:
      - "3000:3000"
    environment:
      - MB_DB_TYPE=postgres
      - MB_DB_DBNAME=********
      - MB_DB_PORT=5432
      - MB_DB_USER=************
      - MB_DB_PASS=compose-postgres
      - MB_DB_HOST=db
      - MB_ENCRYPTION_SECRET_KEY=***********

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM