Synology上Homechart Docker容器无法连接PostgreSQL容器求助
群晖Portainer部署Homechart无法连接PostgreSQL的问题排查与解决
部署配置
version: "3" services: homechart: depends_on: - postgres environment: HOMECHART_POSTGRESQL_HOSTNAME: postgres HOMECHART_POSTGRESQL_PASSWORD: xxxxxxxx HOMECHART_POSTGRESQL_USERNAME: postgres HOMECHART_APP_ADMINEMAILADDRESSES: abc@gmail.com HOMECHART_APP_BASEURL: https://web.homechart.app HOMECHART_APP_DEBUG: true HOMECHART_SMTP_FROMADDRESS: abc@gmail.com HOMECHART_SMTP_HOSTNAME: xxx.synology.me HOMECHART_APP_NOEMAILDOMAINS: HOMECHART_SMTP_REPLYTO: noreply@xxx.synology.me # HOMECHART_SMTP_PORT: # HOMECHART_SMTP_PASSWORD: # HOMECHART_SMTP_USERNAME: image: candiddev/homechart:latest ports: - "3030:3000" restart: always postgres: environment: POSTGRES_PASSWORD: xxxxxxxx image: postgres:14 restart: always volumes: - postgres:/var/lib/postgresql/data volumes: postgres: {}
错误日志
2:5432: connect: connection timed out' requestID='b2179ea2971a6f5f4c1537ac0a8ea1cf' [ERROR] function="models.Setup:885" error='Unable to connect to database' success=false status=false [ERROR] function="tasks.CheckUpdate:178" error='Unable to perform action' success=false status=false debug='Get "https://web.homechart.app/api?p=server": dial tcp: lookup web.homechart.app on 127.0.0.11:53: read udp 127.0.0.1:42087->127.0.0.11:53: i/o timeout'
排查与解决步骤
1. 确认PostgreSQL容器状态
- 在Portainer中查看postgres容器的运行状态,确保处于
running状态 - 查看postgres容器的日志,检查是否有初始化失败、权限错误或端口绑定异常的信息
2. 测试容器间网络连通性
- 进入homechart容器的终端,执行
ping postgres,确认是否能解析到postgres容器的IP并正常连通 - 用
nc -zv postgres 5432或telnet postgres 5432测试5432端口是否开放,若连接失败说明端口未正常监听
3. 检查PostgreSQL配置
- 进入postgres容器,查看
/var/lib/postgresql/data/postgresql.conf中的listen_addresses参数,确认设置为*(允许所有地址监听) - 检查
/var/lib/postgresql/data/pg_hba.conf,添加或确认存在允许homechart网段连接的规则,例如:host all postgres 0.0.0.0/0 md5
4. 核对环境变量配置
- 确认
HOMECHART_POSTGRESQL_PASSWORD与postgres容器的POSTGRES_PASSWORD完全一致,无拼写错误或多余空格 - 若未指定
HOMECHART_POSTGRESQL_PORT,默认是5432,需确认postgres容器未修改默认端口
5. 修复DNS解析问题
日志中存在域名解析超时的错误,可在docker-compose中为容器指定公共DNS服务器,解决容器内DNS解析异常:
services: homechart: # 其他配置不变 dns: [8.8.8.8, 1.1.1.1] postgres: # 其他配置不变 dns: [8.8.8.8, 1.1.1.1]
需要补充的排查信息
- postgres容器的完整运行日志(Portainer中进入postgres容器,查看全部日志)
- 容器所属Docker网络的详情:执行
docker network inspect <网络名称>(网络名称可在Portainer的容器详情页查看),输出结果 - 在homechart容器终端执行
nslookup postgres的输出结果 - 群晖Docker的网络设置(是否启用自定义DNS、是否有防火墙规则限制容器间通信)
内容的提问来源于stack exchange,提问作者A j
相关产品推荐
相关产品推荐

