无法从 docker 容器.NET Core App到主机 droplet 上的 postgreSQL

问题描述

我应该使用什么连接字符串从我的 Docker 容器(.NET Core 应用程序)连接到安装在主机 Droplet 上的 Postgresql 数据库。容器和数据库都在同一个液滴上。 导航到网站工作但出现错误

加载资源失败:服务器响应状态为 400 (错误请求)

尝试与数据库通信时。

这是我的连接字符串:

  "ConnectionStrings": {
    "DefaultConnection": "host=;database=my_db;username=username;password=password"
  }

我已经为连接字符串中的主机部分尝试了公共 IP 和私有 IP,但没有成功。

这里应该使用什么?

[https://www.digitalocean.com/community/questions/can-t-communicate-from-docker-container-net-core-app-to-postgresql-on-host-droplet?utm_content=can- t-communicate-from-docker-container-net-core-app-to-postgresql-on-host-droplet&utm_medium=community&utm_source=linkshare][1]

解决方法

在 docker 命令中使用 --net=host 实际上修复了它!

docker run -d -p 5000:5000 --net=host