为了账号安全,请及时绑定邮箱和手机立即绑定

无法初始化数据库,出现错误无法连接到 `host=user_db user=gorm

无法初始化数据库,出现错误无法连接到 `host=user_db user=gorm

Go
慕工程0101907 2022-07-11 16:58:29
发送gorm.io/gorm v1.20.6gorm.io/driver/postgres v1.0.错误文本user_1     | [error] failed to initialize database, got error failed to connect to `host=user_db user=gorm database=gorm`: dial error (dial tcp 172.18.0.2:9920: connect: connection refused)user_1     | panic: failed to connect to `host=user_db user=gorm database=gorm`: dial error (dial tcp 172.18.0.2:9920: connect: connection refused)所有日志$ docker-compose upStarting urlshortener_user_db_1 ... doneStarting urlshortener_user_1    ... doneStarting urlshortener_gateway_1 ... doneAttaching to urlshortener_user_db_1, urlshortener_user_1, urlshortener_gateway_1user_db_1  | user_db_1  | PostgreSQL Database directory appears to contain a database; Skipping initializationuser_db_1  | user_db_1  | 2020-11-13 04:21:54.059 UTC [1] LOG:  starting PostgreSQL 13.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bituser_db_1  | 2020-11-13 04:21:54.059 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432user_db_1  | 2020-11-13 04:21:54.059 UTC [1] LOG:  listening on IPv6 address "::", port 5432user_db_1  | 2020-11-13 04:21:54.070 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"gateway_1  | [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.gateway_1  | gateway_1  | [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.gateway_1  |  - using env:      export GIN_MODE=releasegateway_1  |  - using code:     gin.SetMode(gin.ReleaseMode)gateway_1  | 
查看完整描述

1 回答

?
慕无忌1623718

TA贡献1744条经验 获得超4个赞

因为图像postgres:alpine是被暴露的端口5432

尝试将连接字符串中的端口 更改- 9920:9920- 5432:5432port=5432


查看完整回答
反对 回复 2022-07-11
  • 1 回答
  • 0 关注
  • 183 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号