I'm using Hasura's 'one-click' deploy to Digital Ocean. The postgres instance works great, but I'm using NextAuth.js to authenticate users. The postgres instance isn't accessible via Nextauth.
This is my docker-compose
file:
version: '3.6'
services:
postgres:
image: postgres:12
restart: always
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgrespassword
graphql-engine:
image: hasura/graphql-engine:v1.3.3
depends_on:
- "postgres"
restart: always
environment:
# database url to connect
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
## enable the console served by server
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set "false" to disable console
## enable debugging mode. It is recommended to disable this in production
HASURA_GRAPHQL_DEV_MODE: "true"
## uncomment next line to set an admin secret
# HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
command:
- graphql-engine
- serve
caddy:
image: caddy/caddy
depends_on:
- "graphql-engine"
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_certs:/root/.caddy
volumes:
db_data:
caddy_certs:
And this is what running docker-compose ps
shows in the terminal:
Name Command State Ports
---------------------------------------------------------------------------------------------------------------------
hasura_caddy_1 caddy run --config /etc/ca ... Up 2019/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
hasura_graphql-engine_1 graphql-engine serve Up
hasura_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
As you can see from the docker-compose
file, I've tried mapping the ports. I've also tried going into /var/lib/docker/containers/<container_hash>
and editing the hostconfig.json
to bind ports, with no success. Further, I've tried editing the postgresql.conf
to accept all IPs with no success.
This is what I pass in the database
value to NextAuth:
"postgres://postgres:postgrespassword@<DROPLET'S_IP>:5432/postgres"
There's no errors visible, but the user isn't generated in the DB, thus my guess that there's no connection. NextAuth doesn't log any errors to the console.
And if I try to connect using psql
from the command line using the following, the connection times out.
psql -h <DROPLET_IP> -p 5432 -d postgres -U postgres
I've also found that Hasura's droplet comes with ufw as a firewall and blocks traffic on all ports except 80 and 22, but even after adding in port 5432, there's no improvement.
Clearly, I know nothing about Docker or containers. I'm looking forward to someone telling me what simple, obvious mistake I've made.
Thanks!
question from:
https://stackoverflow.com/questions/65877915/how-can-i-expose-a-postgres-instance-on-a-do-container-using-hasura-and-nextauth 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…