Docker, SQL Server
November 6, 2017 - Docker, SQL Server
First step is to use SQL Server Management Studio to generate scripts from an existing database. Use the mssql Visual Studio Code extension to connect and manage your database! Microsoft's documentation: Run the SQL Server Docker image on Linux, Mac, or Windows. Share: Twitter Facebook LinkedIn. About David Neal.
Install and Run SQL Server Docker Container on Mac
Like most people, I use Mac , Windows as well Linux OS for development and testing purposes. Primarily I use Mac for Development purpose. I have few projects which uses SQL Server as Data Storage Layer. Setting up Docker Container on Mac and Opening up the ports was pretty easy and doesn’t take more than 10 Minutes.
Steps followed :
- Install Docker
- Pull SQL Server Docker Image
- Run SQL Server Docker Image
- Install mssql Client
- Install Kitematic
- Open the Ports to connect to SQL Server from the network
- Setup port forwarding to enable access outside the network
Install Docker :
Get Docker dmg image and install. Just follow the prompts and its very straight forward.
https://docs.docker.com/docker-for-mac/install/#download-docker-for-machttps://download.docker.com/mac/stable/Docker.dmg
Visual Studio For Mac Download
Once you have installed docker , you can verify the installation and version.
docker pull microsoft/mssql-server-linux:2017-latest |
Create SQL Server Container from the Image and Expose it on port 1433 ( Default Port )
docker run-d--name macsqlserver-e'ACCEPT_EULA=Y'-e'SA_PASSWORD=Passw1rd'-e'MSSQL_PID=Developer'-p1433:1433microsoft/mssql-server-linux:2017-latest |
-d: this launches the container in daemon mode, so it runs in the background
–name name_your_container (macsqlserver): give your Docker container a friendly name, which is useful for stopping and starting containers from the Terminal.
-e ‘ACCEPT_EULA=Y: this sets an environment variable in the container named ACCEPT_EULAto the value Y. This is required to run SQL Server for Linux.
-e ‘SA_PASSWORD=Passw1rd’: this sets an environment variable for the sa database password. Set this to your own strong password. Also required.
-e ‘MSSQL_PID=Developer’: this sets an environment variable to instruct SQL Server to run as the Developer Edition.
-p 1433:1433: this maps the local port 1433 to the container’s port 1433. SQL Server, by default, listens for connections on TCP port 1433.
microsoft/mssql-server-linux: this final parameter tells Docker which image to use
Install SQL Client for MAC
If you don’t have npm installed in Mac, install homebrew and node.
2 4 | ruby-e'$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)' node-v |
2 4 6 | Connecting tolocalhost...done sql-cli version0.6.2 mssql>select *from sys.dm_exec_connections |
Get External Tools to Manage Docker
Kitematic
Open Up the Firewall to connect to SQL Server from outside the Host
Visual Studio
Ensure your firewall is configured to allow the connections to the SQL Server. I turned of “Block all incoming connections” and enabled “Automatically allow downloaded signed software to receive incoming connections”. Without proper firewall configurations, you won’t be able to connect to the SQL Server outside the host.
Ensure Firewall allows the incoming connections to the Docker
Connecting from the Internet ( Port forwarding Setup )
Lets say you want to connect to the SQL Server you setup from outside the network or from anywhere via internet,you can setup port forwarding.
Get your public facing IP and setup the port forwarding for Port 1433 ( SQL Server port you have setup your docker container ). If its setup correctly , you should be able to telnet into that port to verify the connectivity.
Unless you absolutely require it , its very bad idea to expose the SQL Server to internet. It should be behind the network , only your webserver should be accessible via internet.
Troubleshooting :
While launching docker container , if you get the error saying that it doesn’t have enough memory to launch SQL Server Container, go ahead and modify the memory allocation for docker container.
- This image requires Docker Engine 1.8+ in any of their supported platforms.
- At least 3.25 GB of RAM. Make sure to assign enough memory to the Docker VM if you’re running on Docker for Mac or Windows.
I have setup this way.
Docker Memory configs
If you don’t provision enough memory, you will error like this.
Look into Docker logs
Following command ( docker ps -a and docker logs mcsqlserver ) shows list of running processes and docker logs.
Microsoft Visual Studio For Mac
Visual Studio For Mac Os X
2 4 6 8 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9ea3a24563f9microsoft/mssql-server-linux:2017-latest'/bin/sh -c /opt/m...'About an hour ago Up About an hour0.0.0.0:1433->1433/tcp macsqlserver 2017-10-0823:06:52.29Server Setup step iscopying system data file'C:templatedatamaster.mdf'to'/var/opt/mssql/data/master.mdf'. 2017-10-0823:06:52.36Server Setup step iscopying system data file'C:templatedatamastlog.ldf'to'/var/opt/mssql/data/mastlog.ldf'. 2017-10-0823:06:52.36Server Setup step iscopying system data file'C:templatedatamodel.mdf'to'/var/opt/mssql/data/model.mdf'. 2017-10-0823:06:52.38Server Setup step iscopying system data file'C:templatedatamodellog.ldf'to'/var/opt/mssql/data/modellog.ldf'. |
Security:
I highly recommend to create least privileged accounts and disable SA login. If you are exposing your SQL Server to internet, there are ton of hacking and pentest tools which uses sa login for brute force attack.
Today we are announcing the release of Visual Studio for Mac version 7.6. Our focus with this release has been to improve product reliability in various areas, with a special focus on the code editing experience. We have also made several fixes that improve IDE performance. Finally, we’ve extended our support for Azure functions with the addition of new templates and the ability to publish your function to Azure from within the IDE.
This post highlights the major improvements in this release. To see the complete list of changes, check out the Visual Studio for Mac version 7.6 Release Notes. You can get started by downloading the new release or updating your existing install to the latest build available in the Stable channel.
Improving reliability of the Code Editor
We’ve focused our attention on improving the reliability of the code editor in Visual Studio for Mac and have addressed several issues with the code editor. In particular, we want to highlight the following fixes to issues many of you have reported:
Visual Studio For Mac Os
- We fixed an issue where Quick Fix menu items don’t display if source analysis is disabled.
- We also addressed a widely reported issue where tooltips wouldn’t disappear.
- We fixed an issue where IntelliSense seems to fail, resulting in red “squiggles” continuing to hang around in the editor even though there were no errors.
- We improved IntelliSense for F# developers. There was an issue where you could not use “.” for autocompletion, but we’ve fixed this and various other F# IntelliSense issues.
- We made improvements to JavaScript syntax highlighting.
Improving performance of the IDE
One of the top reported bugs in previous releases has been performance issues in the editor. Having a fast and reliable code editor is a fundamental part of any IDE and an important part of any developer’s workflow, so we’ve made some improvements in this area:
- We improved tag-based classification for C# with PR #4740 by reusing existing Visual Studio for Windows code, which should improve typing performance in the editor.
- We now support no-op restore of NuGet packages when opening a solution. This change speeds up NuGet restores on solution load.
We’ve also added many more small fixes that improve startup time and reduce memory consumption of the IDE.
Richer support for Azure Functions
Azure functions are a great way to quickly get up and running with a serverless function in just a few minutes. With this release, we have introduced new templates for you to choose from when creating your Azure Functions project:
Visual Studio For Mac
These new templates allow you to configure access rights, connection strings, and any other binding properties that are required to configure the function. For information on selecting a template, refer to the Available function templates guide.
Another major part of the Azure functions workflow that we are introducing with this release is publishing of functions from Visual Studio for Mac to the Azure Portal. To publish a function, simply right-click on the project name and select Publish > Publish to Azure. You’ll then be able to publish to an existing Azure App Service or use the publishing wizard to create a new one:
Visual Studio For Mac And Sql Server
For information on publishing to Azure from Visual Studio for Mac, see the Publishing to Azure guide.
Share your Feedback
Addressing reliability and performance issues in Visual Studio for Mac remains our top priority. Your feedback is extremely important to us and helps us prioritize the issues that are most impacting your workflow. There are several ways that you can reach out to us:
- Use the Report a Problem tool in Visual Studio for Mac.
- We are enhancing the Report a Problem experience by allowing you to report a problem without leaving the IDE. You’ll have the ability to automatically include additional information, such as crash logs, that will help our Engineering team narrow down the root cause of your report more effectively. This will be introduced in an upcoming servicing release to 7.6 that will be available in the Stable channel within the next few weeks.
- You can track your issues on the Visual Studio Developer Community portal where you can ask questions and find answers.
- In addition to filing issues, you can also add your vote or comment on existing issues. This helps us assess the impact of the issue.