我正在使用 Hasura 的“一键式”部署到 Digital Ocean。postgres 实例运行良好,但我使用 NextAuth.js 对用户进行身份验证。无法通过 Nextauth 访问 postgres 实例。
这是我的docker-compose
文件:
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:
这就是docker-compose ps
终端中运行显示的内容:
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
从docker-compose
文件中可以看出,我已经尝试映射端口。我也尝试进入/var/lib/docker/containers/<container_hash>
并编辑hostconfig.json
绑定端口,但没有成功。此外,我尝试编辑postgresql.conf
以接受所有 IP,但没有成功。
这就是我将database
值传递给 NextAuth 的内容:
"postgres://postgres:postgrespassword@<DROPLET'S_IP>:5432/postgres"
没有可见的错误,但用户不是在数据库中生成的,因此我猜测没有连接。NextAuth 不会将任何错误记录到控制台。
如果我尝试psql
使用以下命令从命令行连接,则连接超时。
psql -h <DROPLET_IP> -p 5432 -d postgres -U postgres
我还发现 Hasura 的 droplet 带有 ufw 作为防火墙,并阻止除 80 和 22 之外的所有端口上的流量,但即使添加了端口 5432,也没有任何改善。
显然,我对 Docker 或容器一无所知。我期待有人告诉我我犯了什么简单、明显的错误。
谢谢!