Connect to PostgreSQL 0.0.0.0 / Docker

Hello!
I have a very interesting issue which might be interesting to other developers who love AdonisJS.

I run AdonisJS and PG in docker in two containers:

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                            NAMES
2c30b1f66607        syndicate_app          "npm start"              9 minutes ago       Up 4 minutes        0.0.0.0:3333->3333/tcp, 0.0.0.0:9229->9229/tcp   syndicate_js
8f0224c55320        postgres:11.3-alpine   "docker-entrypoint.s…"   9 minutes ago       Up 4 minutes        0.0.0.0:54320->5432/tcp                          syndicate_db

From local console when I can connect to PG database without any errors:

$ adonis migration:run
Nothing to migrate

When I open website in the browser I have an error:

connect ECONNREFUSED 0.0.0.0:54320

I think the problem is that the current host of AdonisJS container is the same as PG - 0.0.0.0.

Who can help to solve this issue?

2 Likes

Hi @glodov

I am using quite same setup and everything works fine.
Only difference seems to be, that I expose port 5432 for PG

Can you share your DB host and port in .env and config/database.js?

Also, after doing changes in .env files you have to manually restart Adonis API for it to take effect. Since --dev mode does not autorestart on .env changes.