sourcefuse / loopback4-starter

Loopback 4 starter application. Multi-tenant architecture supported. Authentication, Authorization, Soft deletes, environment vars, Audit logs, included.
MIT License
158 stars 59 forks source link

Cannot Access Postgres when application is containerized #37

Closed sherif2011 closed 4 years ago

sherif2011 commented 4 years ago

This is more of a question than a bug.

Here is my repository: https://github.com/sherif2011/docker-admin/

I am trying to containerize (through docker) my application. You can start application by running "./admin.sh run" This will spin up containers for Admin (application), Redis and Postgres. If you try running http://127.0.0.1/explorer an the following error will appear:

Error: connect ECONNREFUSED 127.0.0.1:5432 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14) Emitted 'error' event at: at PgdbDataSource.postInit (/home/node/app/node_modules/@loopback/repository/node_modules/loopback-datasource-juggler/lib/datasource.js:486:16) at PendingItem.callback (/home/node/app/node_modules/loopback-connector-postgresql/lib/postgresql.js:103:17) at client.connect (/home/node/app/node_modules/pg-pool/index.js:248:23) at Connection.connectingErrorHandler (/home/node/app/node_modules/pg/lib/client.js:163:14) at Connection.emit (events.js:198:13) at Socket.reportStreamError (/home/node/app/node_modules/pg/lib/connection.js:71:10) at Socket.emit (events.js:198:13) at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at process._tickCallback (internal/process/next_tick.js:63:19)

If I stop admin container, and nom run start, application will run fine and will be able to access Postgres.

Meaning that only when the main application (Admin) is containerized, that it's not able to access Postgres.

Can you provide assistance on this one? Am I doing something wrong?

Again here is my repository: https://github.com/sherif2011/docker-admin/

sherif2011 commented 4 years ago

Nevermind, I was able to figure it out. Simply containers get assigned their own IP addresses so Postgres couldn't be accessed through localhost.