Docker - NO DB + Local DB

Hello everyone,

I created a new target (development - local) with docker with no Database (only Redis).
Then I created a new database on my localhost Postgres (port 5432).
On the new target, I changed the db connection to use the new server and ran the migrations and then imported data from my docker database to this new server.

On Database manager and PGAdmin I can see data and run queries, the problem is with the server actions, it’s returning:

status": "500", "code": "ENOTFOUND", "message": "getaddrinfo ENOTFOUND db", "stack": "Error: getaddrinfo ENOTFOUND db\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)"

I see that some people ran across this same problem with external databases, but not with local ones.

As suggested in another topic by @salvuccicarlos, I copied the app folder from. docker_target to docker_no_db_target and it’s still not working.

On the target folder, database/db.json and app/modules/connections/db.json are with the correct credentials.

Is this a bug or Am I doing something wrong?
This process is part of having Digital Ocean’s managed database in our production environment.

Many thanks!

@George @Teodor? :innocent: :grimacing: :exploding_head:

Hi Otavio,

You shouldn’t need to copy any files, just make sure you create a database connection called db in your local development target and let it connect to localhost with the given port. That’s all

Hey @george!
Thanks! This is exactly what I did, but keep showing when running server actions:

status": "500", "code": "ENOTFOUND", "message": "getaddrinfo ENOTFOUND db", "stack": "Error: getaddrinfo ENOTFOUND db\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)

Copy files was an attempt! :smiley:

Well you haven’t edited your server connect database connection settings - it has “db” as server address instead of localhost. Probably because you copied the docker based connection.

1 Like

So I need to create a new connection, with a different name and change all my server actions on this target to this new name?

No, as I said above create a connection with the name db and make sure it has the right credentials

humm…this is what I did! The connection works, I can access the database on Wappler DB Manager and PGAdmin…on server actions, it’s still db as connection but the action doesn’t run, returning 500 error!

Target (no database)

Successfull connection to the local postgres DB

View Data on Wappler DB Manager

Server Action on the new target (same shown above)

Output of the above server action

You have to enter the right database connection options in the global database connections in server connect when having the target active.

@george, Thanks for your help!!

I recreated the target and the error is different now! Still can connect database via Wappler DB Manager and the credentials on globals are correct!

This is my lsof result:

You can’t use 127.0.0.1 because NodeJS is running inside a container (“virtual machine”)

You have to use host.docker.internal to access your host’s IP address

Reference:

2 Likes

thanks @Apple! Right on! Awesome! Thanks @George for your time as well!

1 Like

This is very useful @Apple ! Learned also something new!

2 Likes

hello @Apple!

We are trying to do the same on a linux machine.
I search over the internet and for the host.docker.internal to work on linux machine, need to add the below instruction on docker compose file

extra_hosts:
      - "host.docker.internal:host-gateway"

I added below the “web” directive but still not working.
Have you had to make it work on a linux SO machine?

Best!

Hi Otavio,

I haven’t tried with Linux, but I did a search and you can try connecting to IP address 172.17.0.1, does it work?

Hello @Apple! Thanks for your answer!

For linux + postgres changes on some files:

Docker compose:

extra_hosts:
      - "host.docker.internal:172.17.0.1"

In postgresql.conf, change listen_addresses to listen_addresses = '*'

In pg_hba.conf, add this line

host    all             all             0.0.0.0/0               md5

Restart postgresql service using, sudo service postgresql restart

Use host.docker.internal hostname to connect database from Server, on Global DB config