简体   繁体   English

无法连接到Docker上的SQL数据库

[英]Cannot connect to SQL Database on Docker

I have configured docker with db on it 我已经在docker上配置了db

Here is how I download sql 这是我下载sql的方法

docker pull microsoft/mssql-server-linux:2017-latest

Then I do this command 然后我执行此命令

docker run -e "ACCEPT_EULA=Y" -e  'SA_PASSWORD=$cthulhu1988' -p 1433:1433 --name test -d microsoft/mssql-server-linux:2017-latest

and then I tried to connect to it via this command 然后我尝试通过此命令连接到它

docker exec -it test /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '$cthulhu1988'

But I get this error 但是我得到这个错误

**Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'..**

UPDATE 更新

I make ipconfig And tried to do this with my Ipv4 address 我制作了ipconfig并尝试使用我的Ipv4地址执行此操作

docker exec -it test /opt/mssql-tools/bin/sqlcmd -S 10.0.75.1 -U SA -P '$cthulhu1988'

Now I have this errors 现在我有这个错误

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired. Sqlcmd:错误:SQL Server的Microsoft ODBC驱动程序17:登录超时已过期。 Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x102. Sqlcmd:错误:SQL Server的Microsoft ODBC驱动程序17:TCP提供程序:错误代码0x102。 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. Sqlcmd:错误:SQL Server的Microsoft ODBC驱动程序17:建立与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. 检查实例名称是否正确以及SQL Server是否配置为允许远程连接。 For more information see SQL Server Books Online.. 有关更多信息,请参见SQL Server联机丛书。

I Cheched, tcp\\ip enabled 我检查了一下,启用了tcp \\ ip

Where can be my mistake? 我的错误在哪里?

Your password does not appear to be the issue. 您的密码似乎不是问题。 I connected just fine and can't recreate the issue. 我连接正常,无法重现该问题。 Change your port mapping and try again: 更改端口映射,然后重试:

docker run -e "ACCEPT_EULA=Y" -e  'SA_PASSWORD=$cthulhu1988' -p 1488:1433 --name test -d microsoft/mssql-server-linux:2017-latest

In my case, the password "$cthulhu1988" does not pass complexity validation. 在我的情况下,密码“ $ cthulhu1988”未通过复杂性验证。 Instead of receiving an error, the container starts without any sign of an error. 容器没有收到错误,而是启动时没有任何错误迹象。 However, I can then no longer login as SA. 但是,之后我将无法再以SA身份登录。

I stopped and removed my container, then re-created it with "docker run" but this time I changed the password to 我停止并移除了容器,然后使用“ docker run”重新创建了容器,但是这次我将密码更改为

1Secure*Password1 1安全*密码1

Now having a complexity-valid password, finally I am able to log in as SA. 现在有了复杂性有效的密码,终于可以以SA身份登录了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM