如何从主机连接到数据库 - sql 容器中的服务器 运行 under docker compose
How to connect to the database from host - sql server in container running under docker compose
我是运行Sql容器上的服务器。我已经设置了 docker-compose,所有服务都能够连接到数据库以执行设计时 entity framework 核心迁移。
我想从主机连接到数据库。这似乎不适用于以下代码(使用 "port")。我得到
"
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-编写yaml文件:
version: '3.4'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
container_name: sqlservice
ports:
- 1433:1433
etc...
非常感谢任何想法。
谢谢 paulsm4
MS 文档的 link 给出了答案:
答案:
使用本地机器的 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 检查给出的 IP 地址 - 这两个都失败了)
我是运行Sql容器上的服务器。我已经设置了 docker-compose,所有服务都能够连接到数据库以执行设计时 entity framework 核心迁移。
我想从主机连接到数据库。这似乎不适用于以下代码(使用 "port")。我得到
"
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-编写yaml文件:
version: '3.4'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
container_name: sqlservice
ports:
- 1433:1433
etc...
非常感谢任何想法。
谢谢 paulsm4
MS 文档的 link 给出了答案:
答案: 使用本地机器的 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 检查给出的 IP 地址 - 这两个都失败了)