Home > Software design >  PostgreSQL metabase connection refused
PostgreSQL metabase connection refused

Time:10-14

I am trying to configure postgres to run with springboot and metabase. 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 :

 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.

And yet, It doesn't seem to work. Any help on this issue? (please find my docker-compose file below)

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=********

CodePudding user response:

Try changing MB_DB_HOST in the metabase environmental variables from 0.0.0.0 to db.

CodePudding user response:

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 :

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=***********
  • Related