Connecting to Postgres DB with "forestadmin/toolbelt projects:create" command failed ECONNREFUSED

:warning:This is a template you must use to report issues. :warning:
You can also drag images, videos and include Preformatted text.

Feature(s) impacted

i can’t create a connection with postgresSQL 12 running inside a docker in a Ubuntu 16.04 server

I’m using the adapted command

docker run --rm --init -it -v `pwd`:/usr/src/app -v ~/.forest.d:/usr/src/cli/.forest.d -e TOKEN_PATH="/usr/src/cli" forestadmin/toolbelt projects:create "LPI-001" --databaseConnectionURL "postgres://postgres:xxxxx@127.0.0.1:5432/postgres" --databaseSchema "public" --applicationHost "127.0.0.1" --applicationPort "3310"

√ Creating your project on Forest Admin
× Cannot connect to the database due to the following error:
× {"name":"SequelizeConnectionRefusedError","parent":{"errno":-111,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":5432},"original":{"errno":-111,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":5432}}

Observed behavior

I can’t connect to the postgres database the connection string is correct, i’m able to connect with a psql client locally and remotely, the following command return ok

 pg_isready -d "postgres://postgres:xxxxxx@127.0.0.1:5432/postgres"
127.0.0.1:5432 - accepting connections

Expected behavior

i expect the connection to the DB to be ok

Failure Logs

√ Creating your project on Forest Admin
× Cannot connect to the database due to the following error:
× {"name":"SequelizeConnectionRefusedError","parent":{"errno":-111,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":5432},"original":{"errno":-111,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":5432}}

Context

Please provide in this mandatory section, the relevant information about your configuration:

  • Project name: LPI
  • Team name: LPI
  • Environment name: ubuntu 16.04
  • Agent type & version: ?
  • Recent changes made on your end if any: remove the host.docker.internal to 127.0.0.1

docker-compose to start postgres:

version: "2"

services:
  postgres:
    image: postgres:12-alpine
    restart: "always"
    ports: 
      - "127.0.0.1:5432:5432"
    volumes:
      - /root/LPI-001/data/db:/var/lib/postgresql:cached
      - /root/LPI-001:/home/docker:delegated
      - /root/LPI-001/docker/.pgpass:/root/.pgpass:ro
    environment:    
      - POSTGRES_USER:postgres
      - POSTGRES_PASSWORD=xxxxxx
    networks:
      - "forest"

networks:
  forest:
    driver: bridge

Hi @Denis_Lamotte

As you are running the cli from inside of a docker container, it is expected that it cannot reach your database at postgres://postgres:xxxxx@127.0.0.1:5432/postgres: the local loopback IP that you are using is the container one, not the host machine.

Can you try the following command?

docker run
  --network=forest
  --rm
  --init
  -it
  -v `pwd`:/usr/src/app
  -v ~/.forest.d:/usr/src/cli/.forest.d
  -e TOKEN_PATH="/usr/src/cli"
  forestadmin/toolbelt projects:create "LPI-001"
  --databaseConnectionURL "postgres://postgres:xxxxx@postgres:5432/postgres"
  --databaseSchema "public"
  --applicationHost "127.0.0.1"
  --applicationPort "3310"

I added --network forest and changed the database url to be the hostname of postgres within docker

Also, did you copy-paste that command from our app?
If yes, I’ll open a bug report

Hi @romaing :slight_smile:

Well i’m running the command as root and not inside a container as the docker command is not recognized inside a container. The connection string is also tested outside the container.
Adding --network=forest does not change the result

docker run --network=forest  --rm --init -it -v `pwd`:/usr/src/app -v ~/.forest.d:/usr/src/cli/.forest.d -e TOKEN_PATH="/usr/src/cli" forestadmin/toolbelt projects:create "LPI-001" --databaseConnectionURL "postgres://postgres:xxxxxx@postgres:5432/postgres" --databaseSchema "public" --applicationHost "127.0.0.1" --applicationPort "3310"
√ Creating your project on Forest Admin
× Cannot connect to the database due to the following error:
× {"name":"SequelizeHostNotFoundError","parent":{"errno":-3008,"code":"ENOTFOUND","syscall":"getaddrinfo","hostname":"postgres"},"original":{"errno":-3008,"code":"ENOTFOUND","syscall":"getaddrinfo","hostname":"postgres"}}

so here the connection string specify the internal host postgres “postgres://postgres:xxxxxx@postgres:5432/postgres” but it seems that he did not find the host named postgres

ok by changing the networks to

networks:
  forest:
    external: true

the connection can establish itself ^^

Thanks @anon39940173

version: "2"

services:
  postgres:
    image: postgres:12-alpine
    restart: "always"
    ports: 
      - "127.0.0.1:5432:5432"
    volumes:
      - /root/LPI-001/data/db:/var/lib/postgresql:cached
      - /root/LPI-001:/home/docker:delegated
      - /root/LPI-001/docker/.pgpass:/root/.pgpass:ro
    environment:    
      - POSTGRES_USER:postgres
      - POSTGRES_PASSWORD=71PGlpi-2022
    networks:
      - "forest"

networks:
  forest:
    external: true
1 Like

hi again @anon39940173 , i’ve update the whole file generated to obtain the dockerflle but i still can’t connect the admin dashboard with postgresSQL?

version: '3.0'

networks:
  forest:
    external: true

services:
  postgres:
    container_name: lpi001_postgres_1
    image: postgres:12-alpine
    restart: "always"
    ports:
      - "127.0.0.1:5432:5432"
    volumes:
      - /root/LPI-001/data/db:/var/lib/postgresql:cached
      - /root/LPI-001:/home/docker:delegated
      - /root/LPI-001/docker/.pgpass:/root/.pgpass:ro
    environment:
      - POSTGRES_USER:${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    networks:
      forest:
        aliases:
          - postgres
  app:
    build:
      context: LPI-001/
      dockerfile: Dockerfile
    container_name: lpi001_app_1
    environment:
      - APPLICATION_PORT=${APPLICATION_PORT}
      - APPLICATION_URL=${APPLICATION_URL}
      - DATABASE_URL=${DATABASE_URL}
      - DATABASE_SCHEMA=${DATABASE_SCHEMA}
      - DATABASE_SSL=${DATABASE_SSL}
      - FOREST_AUTH_SECRET=${FOREST_AUTH_SECRET}
      - FOREST_ENV_SECRET=${FOREST_ENV_SECRET}
    ports:
      - "${APPLICATION_PORT}:${APPLICATION_PORT}"
    volumes:
      - /root/LPI-001/LPI-001/:/usr/src/app
      - /usr/src/app/node_modules
    networks:
      forest:
        aliases:
          - app

adminforest_proxy_process_running

But i can’t connect the datasource within my admin panels, the process is waiting until a timeout occur :frowning:
https://app.forestadmin.com/projects

Using a browser, can you connect to http://localhost:3310/forest ?

(Replace 3310 by the APPLICATION_PORT variable)

Hi @romaing :slight_smile:
The containers run with docker on a server where the port 3310 is not normally public. I use an Nginx as reverse proxy to all others applications.
So i’ve change the docker to be available directly under
http://www.grabmyevents.com:3310/forest -> redirect to http://www.grabmyevents.com:3310/

On the console side

> lynx http://127.0.0.1:3310/forest

Looking up 127.0.0.1:3310
Making HTTP connection to 127.0.0.1:3310
Sending HTTP request.
HTTP request sent; waiting for response.
Alert!: HTTP/1.1 204 No Content

checking the headers:

curl -I http://127.0.0.1:3310/forest
HTTP/1.1 204 No Content
X-Powered-By: Express
Vary: Origin
Access-Control-Allow-Credentials: true
Date: Tue, 14 Jun 2022 07:40:37 GMT
Connection: keep-alive
Keep-Alive: timeout=5

the dockers seems to be running

the logs of forest app:

docker logs -f lpi_app_001

> lpi-001@0.0.1 start /usr/src/app
> node ./server.js

Your application is listening on port 3310.
[forest] 🌳🌳🌳  Checking need for apimap update...
[forest] 🌳🌳🌳  No change in apimap, nothing sent to Forest.
Your admin panel is available here: https://app.forestadmin.com/projects
GET / 200 10024 - 14.305 ms
GET /favicon.ico 404 150 - 9.657 ms
GET / 200 10024 - 2.625 ms
GET / 200 10024 - 10.457 ms
GET / 200 10024 - 1.508 ms
GET / 200 10024 - 2.237 ms
GET / 200 10024 - 2.300 ms
GET /forest 204 - - 7.235 ms
GET /forest 204 - - 2.403 ms
GET /forest 204 - - 2.032 ms
HEAD /forest 204 - - 2.028 ms

Reading the docs the models are present:
backend_forestadmin_models

clusters and content-mapping correspond each to a table in postgres