[英]Using SQL Server Management Studio to remote connect to docker container
Context : I am trying to build a development SQL Server that I can continue to learn SQL on and use Microsoft SQL Server Management Studio ( SSMS
) to access on a Windows PC.上下文:我正在尝试构建一个开发 SQL Server,我可以继续在其上学习 SQL 并使用 Microsoft SQL Server Management Studio ( SSMS
) 在 Windows PC 上访问。
So I have the AdventureWorks database sitting on a Docker Container for MS SQL Server 2017 running on a DigitalOcean Ubuntu 16.04 box.因此,我将 AdventureWorks 数据库放在了一个运行在 DigitalOcean Ubuntu 16.04 机器上的 MS SQL Server 2017 的 Docker 容器上。 From my Mac I can remote SSH in to the server, access the container and query the database.在我的 Mac 上,我可以远程 SSH 连接到服务器,访问容器并查询数据库。
However I wish to use SSMS on my Windows PC and am unsure how I begin to connect to the remote box.但是,我希望在我的 Windows PC 上使用 SSMS,但我不确定如何开始连接到远程盒子。 In the picture below, there are no options to specify an SSH key or to even login in to the Ubuntu box, only to access the SQL server.在下图中,没有选项可以指定 SSH 密钥,甚至无法登录 Ubuntu 框,只能访问 SQL 服务器。
Is this even possible?这甚至可能吗?
connect via SSMS using the public IP address, followed by comma separator and then the port (xxx.xx.xx.xxx,port)使用公共 IP 地址通过 SSMS 连接,后跟逗号分隔符,然后是端口 (xxx.xx.xx.xxx,port)
You'll also need the sa credentials to make this work.您还需要 sa 凭据才能完成这项工作。
In your case, Server Name input will become Server IP, port#在您的情况下,服务器名称输入将成为服务器 IP、端口#
No need of ssh, you just need to expose SQL Server service to the internet.不需要 ssh,您只需要将 SQL Server 服务公开到 Internet。
When Using SQL Server Management Studio to connect to the docker container on local machine , you can use localhost ip.使用 SQL Server Management Studio 连接本地机器上的 docker 容器时,可以使用 localhost ip。 In that case Server Name input will become 127.0.0.1,port#在这种情况下,服务器名称输入将变为127.0.0.1,port#
Following instruction of this site solved it for me on Windows Containers: https://www.sqlshack.com/sql-server-with-a-docker-container-on-windows-server-2016/ It was possible to connect to SQL Server instantly from SSMS.按照本网站的说明在 Windows 容器上为我解决了这个问题: https ://www.sqlshack.com/sql-server-with-a-docker-container-on-windows-server-2016/ 可以连接到 SQL从 SSMS 即时服务器。
Give it a try if this is also working on Linux containers with this command:如果这也适用于使用以下命令的 Linux 容器,请尝试一下:
docker run --name mssqltrek-con1 -d -p 1433:1433 -e sa_password=My$eCurePwd123# -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer
After running this you can retrieve the correct ip with:运行此之后,您可以使用以下命令检索正确的 ip:
docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" mssqltrek-con1
In my case it was the Cisco VPN that was blocking the host to connect to container IP.在我的例子中,是 Cisco VPN 阻止了主机连接到容器 IP。 I had to uncheck the "Cisco Any Connect Network Access Manager" as shown in the image below for it to work.我必须取消选中“Cisco Any Connect Network Access Manager”,如下图所示,它才能工作。 It ensures that the VPN no longer manages the connection.它确保 VPN 不再管理连接。
You can connect to SQL docker server您可以连接到 SQL docker 服务器
IP_Of_Machine,Port IP_Of_Machine,端口
Provide User - sa (default) and password.提供用户 - sa(默认)和密码。
you can also do it command>你也可以这样做命令>
docker exec -it <container_id|container_name> /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <your_password> docker exec -it <container_id|container_name> /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <your_password>
This isn't exactly the same problem as the OP's but I created a sql docker container and then couldn't log in to it from SQL Server Management Studio.这与 OP 的问题并不完全相同,但我创建了一个 sql docker 容器,然后无法从 SQL Server Management Studio 登录到它。 It turned out that the sa password I used wasn't secure enough.原来我用的sa密码不够安全。 Once I deleted my container and recreated one with a more secure password it let me connect to it from SQL Server Management Studio.一旦我删除了我的容器并使用更安全的密码重新创建了一个容器,它就可以让我从 SQL Server Management Studio 连接到它。 If you do not specify a strong enough password it still creates the container OK - you just can't log in to it!如果您没有指定足够强的密码,它仍然可以创建容器 - 您只是无法登录它! Hopefully this will save someone some time.希望这可以节省一些时间。
I also faced same issue when I try to connect through SSMS, even I tried with localhost,1433 it doesn't help me out.当我尝试通过 SSMS 连接时,我也遇到了同样的问题,即使我尝试使用 localhost,1433 也无济于事。 enter image description here在此处输入图像描述
After some R&D I found the way to solve it经过一些研发,我找到了解决它的方法
I benefited from the answers on this page, however, i had to go through my own tweak.我从这个页面上的答案中受益,但是,我必须进行自己的调整。 for some reason, in my case, it didnt accept localhost,1433 but it did accept 127.0.0.1,1433出于某种原因,就我而言,它不接受 localhost,1433 但它确实接受了 127.0.0.1,1433
In my case I was using docker-compose
and was unable to connect.就我而言,我使用的是docker-compose
并且无法连接。 I fixed this by explicitly specifying the port in the docker compose file.我通过在 docker compose 文件中明确指定端口来解决此问题。
mysqldb:
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=SuperSecretPassword!23
image: registry/mysqlimage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.