如何将SSMS连接到运行在Docker容器中的Linux SqlServer?

5

我已经在我的电脑上安装了Docker。我已经安装了适用于Linux的SqlServer,并且实例运行正常。

我需要使用SSMS连接到Docker实例。您可以在图片中看到我的个人配置。

安装时,我遵循了这个链接 https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-setup-docker

提前致谢。

enter image description here

当我启动服务器时,我会收到这个消息。
PS C:\Users\Daniele> docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS
NAMES
PS C:\Users\Daniele> docker run  microsoft/mssql-server-linux
This is an evaluation version.  There are [171] days left in the evaluation period.
2017-05-23 07:19:15.12 Server      Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssq
l/data/master.mdf'.
2017-05-23 07:19:15.19 Server      Setup step is copying system data file 'C:\templatedata\mastlog.ldf' to '/var/opt/mss
ql/data/mastlog.ldf'.
2017-05-23 07:19:15.19 Server      Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql
/data/model.mdf'.
2017-05-23 07:19:15.21 Server      Setup step is copying system data file 'C:\templatedata\modellog.ldf' to '/var/opt/ms
sql/data/modellog.ldf'.
2017-05-23 07:19:15.22 Server      Setup step is copying system data file 'C:\templatedata\msdbdata.mdf' to '/var/opt/ms
sql/data/msdbdata.mdf'.
2017-05-23 07:19:15.24 Server      Setup step is copying system data file 'C:\templatedata\msdblog.ldf' to '/var/opt/mss
ql/data/msdblog.ldf'.
2017-05-23 07:19:15.34 Server      Microsoft SQL Server 2017 (CTP2.1) - 14.0.600.250 (X64)
        May 10 2017 12:21:23
        Copyright (C) 2017 Microsoft Corporation. All rights reserved.
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.2 LTS)
2017-05-23 07:19:15.34 Server      UTC adjustment: 0:00
2017-05-23 07:19:15.35 Server      (c) Microsoft Corporation.
2017-05-23 07:19:15.35 Server      All rights reserved.
2017-05-23 07:19:15.35 Server      Server process ID is 4116.
2017-05-23 07:19:15.35 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2017-05-23 07:19:15.36 Server      Registry startup parameters:
         -d /var/opt/mssql/data/master.mdf
         -l /var/opt/mssql/data/mastlog.ldf
         -e /var/opt/mssql/log/errorlog
2017-05-23 07:19:15.37 Server      SQL Server detected 1 sockets with 2 cores per socket and 2 logical processors per so
cket, 2 total logical processors; using 2 logical processors based on SQL Server licensing. This is an informational mes
sage; no user action is required.
2017-05-23 07:19:15.38 Server      SQL Server is starting at normal priority base (=7). This is an informational message
 only. No user action is required.
2017-05-23 07:19:15.39 Server      Detected 3944 MB of RAM. This is an informational message; no user action is required
.
2017-05-23 07:19:15.39 Server      Using conventional memory in the memory manager.
2017-05-23 07:19:15.63 Server      Buffer pool extension is already disabled. No action is necessary.
2017-05-23 07:19:15.76 Server      InitializeExternalUserGroupSid failed. Implied authentication will be disabled.
2017-05-23 07:19:15.76 Server      Implied authentication manager initialization failed. Implied authentication will be
disabled.
2017-05-23 07:19:15.77 Server      Successfully initialized the TLS configuration. Allowed TLS protocol versions are ['1
.0 1.1 1.2']. Allowed TLS ciphers are ['ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM
-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RS
A-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:AES256-GCM-SHA38
4:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA'].
2017-05-23 07:19:15.81 Server      The maximum number of dedicated administrator connections for this instance is '1'
2017-05-23 07:19:15.81 Server      Node configuration: node 0: CPU mask: 0x0000000000000003:0 Active CPU mask: 0x0000000
000000003:0. This message provides a description of the NUMA configuration for this computer. This is an informational m
essage only. No user action is required.
2017-05-23 07:19:15.82 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock
Owner blocks per node.  This is an informational message only.  No user action is required.
2017-05-23 07:19:15.83 Server      In-Memory OLTP initialized on lowend machine.
2017-05-23 07:19:15.88 Server      Database Instant File Initialization: enabled. For security and performance considera
tions see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message
only. No user action is required.
2017-05-23 07:19:15.89 Server      Query Store settings initialized with enabled = 1,
2017-05-23 07:19:15.90 spid7s      Starting up database 'master'.
2017-05-23 07:19:15.91 Server      Software Usage Metrics is disabled.
2017-05-23 07:19:16.12 spid7s      The tail of the log for database master is being rewritten to match the new sector si
ze of 4096 bytes.  3584 bytes at offset 418304 in file /var/opt/mssql/data/mastlog.ldf will be written.
2017-05-23 07:19:16.18 spid7s      Converting database 'master' from version 862 to the current version 868.
2017-05-23 07:19:16.19 spid7s      Database 'master' running the upgrade step from version 862 to version 863.
2017-05-23 07:19:16.21 spid7s      Database 'master' running the upgrade step from version 863 to version 864.
2017-05-23 07:19:16.23 spid7s      Database 'master' running the upgrade step from version 864 to version 865.
2017-05-23 07:19:16.23 spid7s      Database 'master' running the upgrade step from version 865 to version 866.
2017-05-23 07:19:16.24 spid7s      Database 'master' running the upgrade step from version 866 to version 867.
2017-05-23 07:19:16.25 spid7s      Database 'master' running the upgrade step from version 867 to version 868.
2017-05-23 07:19:16.42 spid7s      Buffer pool extension is already disabled. No action is necessary.
2017-05-23 07:19:16.42 spid7s      Resource governor reconfiguration succeeded.
2017-05-23 07:19:16.43 spid7s      SQL Server Audit is starting the audits. This is an informational message. No user ac
tion is required.
2017-05-23 07:19:16.43 spid7s      SQL Server Audit has started the audits. This is an informational message. No user ac
tion is required.
2017-05-23 07:19:16.49 spid7s      SQL Trace ID 1 was started by login "sa".
2017-05-23 07:19:16.50 spid7s      Server name is '29e275920103'. This is an informational message only. No user action
is required.
2017-05-23 07:19:16.50 spid7s      The NETBIOS name of the local node that is running the server is '29e275920103'. This
 is an informational message only. No user action is required.
2017-05-23 07:19:16.52 spid19s     Password policy update was successful.
2017-05-23 07:19:16.52 spid22s     Always On: The availability replica manager is starting. This is an informational mes
sage only. No user action is required.
2017-05-23 07:19:16.53 spid9s      Starting up database 'mssqlsystemresource'.
2017-05-23 07:19:16.53 spid7s      Starting up database 'msdb'.
2017-05-23 07:19:16.54 spid22s     Always On: The availability replica manager is waiting for the instance of SQL Server
 to allow client connections. This is an informational message only. No user action is required.
2017-05-23 07:19:16.55 spid9s      The resource database build version is 14.00.600. This is an informational message on
ly. No user action is required.
2017-05-23 07:19:16.57 spid9s      Starting up database 'model'.
2017-05-23 07:19:16.88 spid7s      The tail of the log for database msdb is being rewritten to match the new sector size
 of 4096 bytes.  512 bytes at offset 52736 in file /var/opt/mssql/data/MSDBLog.ldf will be written.
2017-05-23 07:19:16.94 spid7s      Converting database 'msdb' from version 862 to the current version 868.
2017-05-23 07:19:16.95 spid7s      Database 'msdb' running the upgrade step from version 862 to version 863.
2017-05-23 07:19:16.98 spid19s     A self-generated certificate was successfully loaded for encryption.
2017-05-23 07:19:17.00 spid7s      Database 'msdb' running the upgrade step from version 863 to version 864.
2017-05-23 07:19:17.01 spid19s     Server is listening on [ 0.0.0.0 <ipv4> 1433].
2017-05-23 07:19:17.02 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
2017-05-23 07:19:17.02 Server      Dedicated admin connection support was established for listening locally on port 1434
.
2017-05-23 07:19:17.02 spid9s      The tail of the log for database model is being rewritten to match the new sector siz
e of 4096 bytes.  2048 bytes at offset 75776 in file /var/opt/mssql/data/modellog.ldf will be written.
2017-05-23 07:19:17.02 spid19s     SQL Server is now ready for client connections. This is an informational message; no
user action is required.
2017-05-23 07:19:17.05 spid7s      Database 'msdb' running the upgrade step from version 864 to version 865.
2017-05-23 07:19:17.05 spid7s      Database 'msdb' running the upgrade step from version 865 to version 866.
2017-05-23 07:19:17.06 spid9s      Converting database 'model' from version 862 to the current version 868.
2017-05-23 07:19:17.06 spid9s      Database 'model' running the upgrade step from version 862 to version 863.
2017-05-23 07:19:17.07 spid7s      Database 'msdb' running the upgrade step from version 866 to version 867.
2017-05-23 07:19:17.08 spid7s      Database 'msdb' running the upgrade step from version 867 to version 868.
2017-05-23 07:19:17.09 spid9s      Database 'model' running the upgrade step from version 863 to version 864.
2017-05-23 07:19:17.10 spid9s      Database 'model' running the upgrade step from version 864 to version 865.
2017-05-23 07:19:17.10 spid9s      Database 'model' running the upgrade step from version 865 to version 866.
2017-05-23 07:19:17.10 spid9s      Database 'model' running the upgrade step from version 866 to version 867.
2017-05-23 07:19:17.11 spid9s      Database 'model' running the upgrade step from version 867 to version 868.
2017-05-23 07:19:17.22 spid9s      Polybase feature disabled.
2017-05-23 07:19:17.22 spid9s      Clearing tempdb database.
2017-05-23 07:19:17.71 spid9s      Starting up database 'tempdb'.
2017-05-23 07:19:17.97 spid9s      The tempdb database has 1 data file(s).
2017-05-23 07:19:17.99 spid22s     The Service Broker endpoint is in disabled or stopped state.
2017-05-23 07:19:17.99 spid22s     The Database Mirroring endpoint is in disabled or stopped state.
2017-05-23 07:19:18.00 spid22s     Service Broker manager has started.
2017-05-23 07:19:18.14 spid7s      Recovery is complete. This is an informational message only. No user action is requir
ed.
4个回答

9

这是一个老问题,但当我遇到类似的问题时,我来到了这个帖子。因此,回答这个问题可能对其他人有用。

在我的情况下,它是服务器名称语法问题。SSMS使用ip_address,port_number语法。因此,我必须使用localhost,1433或127.0.0.1,1433进行连接。

实际上,我发现了一个与此相关的SO问题在这里


SSMS 对服务器名称确实很挑剔。localhost,1433 对我有效;谢谢! - Jez

3
如果你在文档中运行了以下命令:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433 -d microsoft/mssql-server-linux
那么容器上的端口会映射到你本地主机的端口。因此,你可以使用localhost和上面指定的密码连接到数据库。
如果这个方法可行,请告诉我!

我尝试了这种方法,但是出现了“无法找到本地主机”的消息。 - daniele3004
也许我需要为 Docker 容器设置 IP 地址?在上一个图片的结果中,端口为 0.0.0.0:1433->1433/tcp。 - daniele3004
Docker会自动分配IP地址。你尝试过使用127.0.0.1代替localhost吗? - Luis Bosquez
与我相同的问题。服务器未找到。 - johnstaveley
如果您在Kitematic中查看,访问IP与docker inspect中的IP不同。然而,这也无法连接。我还尝试添加端口1434,因为日志显示它在此端口上内部监听。但是我也无法使用此端口连接。 - johnstaveley
显示剩余2条评论

0

虽然我来晚了,但我希望这个答案能够帮助未来的某个人。大家好,我也遇到了报告中描述的确切问题。

对我有用的解决方法是按照以下方式连接:

127.0.0.1\{container_name},1433

我使用了以下图片:

mcr.microsoft.com/mssql/server 带有MSSQL_PID Express和端口:

"1433:1433"
"1434:1434/udp"

0

仅使用IP地址(我曾经使用“Ip,1433\Express”遇到同样的问题)。如果您没有使用标准端口,请添加逗号而不是冒号! 但不要使用docker的内部IP。请使用从任务栏设置中获取的docker桌面图标中的IP地址=>网络=>“内部虚拟开关”=>子网地址。(必须在本地主机PC IP范围内)。将最后一个0替换为1。 参见:https://learn.microsoft.com/de-de/sql/linux/sql-server-linux-manage-ssms?view=sql-server-2017 SQL-Auth。 用户=SA PWD请参见docker运行命令的开头。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接