问题描述
我正在使用 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 或容器一无所知。我期待有人告诉我我犯了多么简单、明显的错误。
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)