Using SQL Server Management Studio to remote connect to docker container - sql-server

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.
So I have the AdventureWorks database sitting on a Docker Container for MS SQL Server 2017 running on a DigitalOcean Ubuntu 16.04 box. From my Mac I can remote SSH in to the server, access the container and query the database.
However I wish to use SSMS on my Windows PC and am unsure how I begin to connect to the remote box. 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.
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)
You'll also need the sa credentials to make this work.

In your case, Server Name input will become Server IP, port#
No need of ssh, you just need to expose SQL Server service to the internet.
When Using SQL Server Management Studio to connect to the docker container on local machine, you can use localhost ip. In that case Server Name input will become 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.
Give it a try if this is also working on Linux containers with this command:
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:
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. I had to uncheck the "Cisco Any Connect Network Access Manager" as shown in the image below for it to work. It ensures that the VPN no longer manages the connection.

You can connect to SQL docker server
Using IP of Machine on which docker image is hosted,port
IP_Of_Machine,Port
Provide User - sa (default) and password.
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>

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. It turned out that the sa password I used wasn't secure enough. Once I deleted my container and recreated one with a more secure password it let me connect to it from 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 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

In my case I was using docker-compose and was unable to connect. I fixed this by explicitly specifying the port in the docker compose file.
mysqldb:
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=SuperSecretPassword!23
image: registry/mysqlimage

I also faced same issue when I try to connect through SSMS, even I tried with localhost,1433 it doesn't help me out.
enter image description here
After some R&D I found the way to solve it
Open Kubernetes which will be installed as part of docker toolbox
(mine was win 10 home which will not support hyper-v)
click on sql container which will be in left side of app
copy the IP address which will be in right side of app
use IP address with port like XXX.XXX.XX.XX,1433 along with credentials in SSMS
enter image description here

Related

Connect to SQL Server Express running inside a container from SSMS

I am trying to connect to an instance of SQL Server Express running inside a container from SSMS running on my host machine.
The container was started as follows:
docker pull microsoft/mssql-server-windows-express
docker run -d -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=password" -p 1436:1433 --name mydb microsoft/mssql-server-windows-express
The container is running on the IP address that I got using
docker inspect --format '{{.NetworkSettings.Networks.nat.IPAddress}}' mydb
Now I am trying to connect to this instance, at the above IP address using SSMS, but get the following error:
I get the same error even if I change the case/position of the instance, e.g. 1.2.3.4,1436\SQLExpress, or 1.2.3.4\SQLExpress,1436.
What am I missing?
Possible duplicates:
Cannot connect to SQL Server express from SSMS
Connect to SQL Express with SSMS
But the answers didn't help me.
I have made sure that the container is up and running. I can ping to the IP address of the container.
The username and password are correct.
One thing I could be missing is that the SQL Server authentication is not enabled on the database instance in the container. I am not sure how to do that.
How can I connect to the SQL Server Express instance running inside a container from SSMS?
The original password I had used was weak (no I wasn't using password used in the question, but a different one which was still weak).
After starting a new container with a password which has combinations of uppercase, lowercase, characters, and numbers, I can now log into the database using following settings.

Cannot manage docker-based mysql server from Linux

I installed an mssql server using docker container in an ubuntu EC2 as follows:
sudo docker run --name my_mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<mypassword>" -p 1433:1433 -v /home/ubuntu/db:/var/opt/mssql -d microsoft/mssql-server-linux
sudo netstat -lpnt |grep 1433
shows 1433 is listening
I can login the mssql server using username=sa and password=mypassword using SQLPRO for MSSQL – a database manager, I can then create a database from that manager.
However, if I operate the mssql server from the EC2 in which the mssql server is installed, using the below command,
mysql -h <EC2 IP> -P 1433 -u sa -p
and then provide the password, it just stuck there and finally stop connecting with error message:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
Why I cannot operate mssql server from the ubuntu EC2? How can I do that?
You DB server is MSSQL, and you are trying to connect with MSSQL using Mysql client, which will defiantly not work.
Can I use mysql to connect to SQL Server?
microsoft/mssql-server-linux
you can verify accessibility using
telnet EC2_IP 1433
or you can use sqlcmd or MSSQL client to connect with your DB container.
You're using SQL Server, not MySQL. You can't use another database's tools to connect to it.
You need to use SQL Server's command-line tools:
sqlcmd is the CLI query tool, similar to mysql
bcp is used for bulk import/export
You can also use Azure Data Studio (the unfortunate marketing name of what started as SQL Server Operations Studio). ADS can connect to SQL Server directly and PostgreSQL through an extension
It's a cross-platform editor/IDE similar to Visual Studio Code built for querying, visualizing results, managing databases and executing Python scripts and Jupiter Notebooks. It comes with server and database dashboards out of the box. There are several extensions for advanced monitoring and troubleshooting too.
It's also trivial to create new dashboards based on your own queries: Just copy the visualisations JSON definition into a settings file.

Connecting to SQL Server on host through Windows Server-based container

How do you connect to a SQL Server database on a host (or even in the cloud, as in off the local network) from a windows server-based container?
I've tried using
docker run --net="nat" ...
and
docker run --net="host" ...
to no avail.
Using -p does not seem relevant as I want to container to talk to the SQL Server database not running in a container.
I'm not sure how a custom network bridge can work here but I'm open to trying.

"The semaphore timeout period has expired" on connect to MS SQLServer inside WIndows Container

I have faced with very strange issue.
Host OS is Windows 10 Pro, installed Docker for Windows.
When I run microsoft/mssql-server-windows-developer container using simple command
docker run -d -p 1433:1433 -e sa_password=<SA_PASSWORD> -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer
I can connect to SQL Server via MS SQL Management Studio using server name=localhost. But I can't open Server Properties or open "Attach DB" wizard. There is the same error all the time "The semaphore timeout period has expired".
I can run container with attached DBs and I can execute sql inside MS SQL Management Studio. But when I run my Web Application - I get the same error "The semaphore timeout period has expired" on connect to DB.
Then I tried to connect to SQL Server using IP address which I get via docker container inspect - in my case it was 172.28.93.83. And everything worked as it should - I can manage with SQL Server, my Web Application connects to the DB, etc.
So, what is the issue there? I still want to use localhost to connect to server to have unified connection string in all developers environments.
When I tried to run Linux container - everything worked fine using localhost to connect to server.
I could be important - before I decided to use docker to work with MS SQL Server I had MS SQL Server installed and then uninstalled it. Maybe it made some changes in a routing or network which I have to remove...
I would appreciate any help
Try with increase timeout seconds in connection string.
I solved a similar incident changing the metric to the card generated by Docker.
I put 5000.
Luck.

Is it possible to inventory MSSQL-Linux running within Docker?

Part of my job involves data collection to help size workloads that could be transferred to the cloud. An element of this is being able to enumerate SQL instances within a client's environment for insights such as "hey you have some out of support legacy SQL here that was supposed to be decommed years ago, what's the deal."
With the release of SQL Server 2017, I've just now created an instance of the SQL Server Enterprise 2017 on Linux container (using this image) that I'm running locally on Windows 10. I can connect to the instance via SSMS and SELECT ##VERSION to confirm it's legit, but my question is if it is possible to inventory the device and find the SQL instance without knowing that connection string.
Things I've tried:
-Running on Windows 10 so I believe this is supported via Hyper-V, when I try to go through the Hyper-V manager to connect to the VM Docker spun up, can't get any interface there (which I figured, since Docker emulates apps rather than full VMs)
-Tried to do a sqlcmd -L from the Win10 host device and don't see the instance (Don't have SQL installed on the Windows 10 device I'm running this from)
-I can find the docker image via a docker ps, then exec -it to bash, and use sqlcmd from there, but the sqlcmd -L isn't listed as an option within Linux.
-ipconfig from the host device shows the Docker IP address, but it wouldn't give me the port information so I would have to scan through all the ports which feels dirty.
I'm kind of at a loss at this point. If I didn't explicitly know a Docker container was running MSSQL-Linux, is there any way I could identify that from inventorying the host device? (sorry for the long post)
After banging my head on it for a bit I've found a painful workaround of:
connect to the container's bash using: docker exec -it <container_name> "bash"
then using ps aux | grep sql to list all of the sql processes. The MS image shows up as /opt/mssql/bin/sqlservr from local testing. Once SQL has been identified you can attempt to connect to it using the Docker ip from ipconfig and the port from docker ps
It's not elegant, but it should be possible to automate those steps for use across a set of unknown devices.
Leaving this open for a bit for any better alternatives.

Resources