0

我应该使用什么连接字符串从我的 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 -从-docker-container-net-core-app-to-postgresql-on-host-droplet&utm_medium=community&utm_source=linkshare][1]

4

1 回答 1

0

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

docker run -d -p 5000:5000 --net=host
于 2021-02-15T09:43:13.473 回答