docker-compose - 如何从主机连接到数据库 - 在docker compose下运行的容器中的sql server

标签 docker-compose migration containers entity-framework-core port

我在容器上运行 Sql Server。我已经设置了 docker-compose 并且所有服务都能够连接到数据库以执行设计时 Entity Framework 核心迁移。

我想从主机连接到数据库。这似乎不适用于以下代码(使用“端口”)。我得到

"
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
The network path was not found
" 

docker-compose yaml 文件:
version: '3.4'
    services:
      mssql:
        image: mcr.microsoft.com/mssql/server:2017-latest
        container_name: sqlservice
        ports:
          - 1433:1433
etc...

任何想法都非常感谢。

最佳答案

谢谢 paulsm4

ms 文档的链接给出了答案:

回答:
使用本地机器的IP地址
https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-2017

查找托管容器的机器的 IP 地址。在 Linux 上,使用 ifconfig 或 ip addr。在 Windows 上,使用 ipconfig。

Run sqlcmd specifying the IP address and the port mapped to port 1433 in your container. In this example, that is the same port, 1433, on the host machine. If you specified a different mapped port on the host machine, you would use it her



(我使用的是 0.0.0.0,还尝试了 docker inspect 给出的 IP 地址 - 这两个都失败了)

关于docker-compose - 如何从主机连接到数据库 - 在docker compose下运行的容器中的sql server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53787537/

相关文章:

bash - 抑制或隐藏 Docker "Steps"和控制台中的默认输出

mysql - 如何轻松地从 MySQL 迁移到 PostgreSQL?

c++ - 将模板 typedef 的数组传递给构造函数

C# 应用程序在 docker 中失败并显示 "cannot start service from the command line"但在主机上没有

python - 有或没有 venv 的 Docker?

docker - Traefik + Nextcloud 导致网关故障

amazon-web-services - 从Docker容器登录到AWS Cloudwatch

mysql - 将 Etherpad 数据库从 MySQL 迁移到 Mongodb

migration - 使用 truffle 迁移合约让我可以恢复交易

java - 在 Web 浏览器中无法看到 Java Maven Tomcat-plugin Web 应用程序