gpt4 book ai didi

sql-server - Docker SQL Server 2017在Linux上的连接问题

转载 作者:行者123 更新时间:2023-12-02 19:52:17 25 4
gpt4 key购买 nike

我的Docker linux SQL Server今天无法在我的机器上工作。

我不确定这是防火墙(我已经全部关闭)还是Docker设置(因为我刚刚升级到最新的Docker版本),或者是Docker SQL Server问题(但在较早的同一台机器上运行正常)。

有人可以帮忙吗?

我尝试使用bash

 /opt/mssql-tools/bin/sqlcmd -S localhost,8010 -U SA -P Test123!

错误:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..



docker撰写文件

version: '3'
services:
mssql:
network_mode: lsvc
image: microsoft/mssql-server-linux:2017-latest
container_name: mssql
hostname: mssql
volumes:
- ./.db:/var/opt/mssql/
- /var/opt/mssql/data
- ./sqlinit.sql:/scripts/sqlinit.sql
ports:
- 8010:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Test123!
command:
- /bin/bash
- -c
- |
# Launch MSSQL and send to background
/opt/mssql/bin/sqlservr &
# Wait for it to be available
echo "Waiting for MS SQL to be available"
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , @@servername"
is_up=$$?
while [ $$is_up -ne 0 ] ; do
echo -e $$(date)
/opt/mssql-tools/bin/sqlcmd -l 30 -S mssql -h-1 -V1 -U sa -P Test123! -Q "SET NOCOUNT ON SELECT \"YAY WE ARE UP\" , @@servername"
is_up=$$?
sleep 1
done
# Run every script in /scripts
# TODO set a flag so that this is only done once on creation,
# and not every time the container runs
#for foo in /scripts/*.sql
/opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P Test123! -l 30 -e -i /scripts/sqlinit.sql
#done
# So that the container doesn't shut down, sleep this thread
sleep infinity

最佳答案

我怀疑mssql实例无法启动。

当服务器无法启动时,查看您的docker文件会陷入无限循环。我建议您限制循环中的重试次数,以便您有一个指示服务器启动失败的指示。
或者最好考虑使用 HEALTHCHECK 选项,而不是循环脚本
https://blog.couchbase.com/docker-health-check-keeping-containers-healthy/

要解决问题,请尝试

docker logs <mssql-container-id>

如果这不能提供足够的信息,请尝试连接到容器,因为这是一台简单的机器。
docker exec -it <mssql-container-id> bash

在/ var / opt / mssql / log / errorlog中查找错误
参见 https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-troubleshooting-guide?view=sql-server-ver15

关于sql-server - Docker SQL Server 2017在Linux上的连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59943825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com