Docker-Compose: Postgres Database Connection Error: ECONNREFUSED 127.0.0.1:5432

I want to setup wikijs together with postgres using docker-compose. It works, but only when I use network_mode host. When I want to setuptheir own network, wikijs is not able to connect to postgres, giving me the following error:

Database Connection Error: ECONNREFUSED 127.0.0.1:5432

This is my docker-compose.yml:

version: "3.3"

services:
  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: wiki
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
      POSTGRES_USER: wikijs
    restart: unless-stopped
    volumes:
      - /opt/docker/docker-volumes/postgresql/data:/var/lib/postgresql/data
    secrets:
      - db_password

  wiki:
    image: ghcr.io/requarks/wiki:2
    depends_on:
      - db
    environment:
      DB_TYPE: postgres
      DB_HOST: db
      DB_PORT: 5432
      DB_USER: wikijs
      DB_PASS_FILE: /run/secrets/db_password
      DB_NAME: wiki
      CONFIG_FILE: /wiki/config/config.yml
    restart: unless-stopped
    ports:
     - "4501:4500"
    # Mount config file into container
    volumes:
     - ./config.yml:/wiki/config/config.yml 
    secrets:
      - db_password


secrets:
  db_password:
    file: ./secrets/db_password.txt


volumes:
  db-data:

Please note that I am using ports 4501:4500 because I have a running wikijs instance on 4500 already, with the before-mentioned network_mode host.

Seems the container is still trying to reach 127.0.0.1:5432 instead of db:5432 as you set in DB_HOST

Do you have any code trying to connect to the db?

Hello, indeed the config.yml file was still trying to reach 127.0.0.01:5432. But even after removing the config file from docker-compose.yml, I still get a connection timeout:

Database Connection Error: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

At least we’re looking at a different problem now

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.