【问题标题】:Can't communicate from docker container (.NET Core App) to postgreSQL on host droplet无法从 docker 容器(.NET Core 应用程序)与主机 droplet 上的 postgreSQL 通信
【发布时间】:2021-02-15 09:02:48
【问题描述】:

我应该使用什么连接字符串从我的 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]

【问题讨论】:

    标签: postgresql docker containers asp.net-core-webapi droplet


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-05
      • 2020-10-08
      • 2020-10-16
      • 1970-01-01
      • 2022-11-16
      • 2018-08-31
      • 2019-08-08
      • 1970-01-01
      相关资源
      最近更新 更多