Today I Learned how to Run SQL Server on a Mac using Docker

Working on my code example for my upcoming SQL Saturday 710 talk I ran into a performance issue.  My laptop is an older MacBook Pro and I was trying to run my example on a Windows virtual machine…

What is SQL Saturday?  Good question.

SQL Saturday Logo

SQL Saturday is an entire day of talks, training, and socializing about databases and data storage.  SQL Saturday 710 is on May 5th in Edmonton but there are SQL Saturdays, with different numbers at the end, all around the world on different dates.

Back to my problem which was running my example on a Windows virtual machine running on my older MacBook Pro. I’ve upgraded my MacBook Pro over the years with more RAM and a SSD hard drive the virtual machine is still not responsive enough for my liking with SQL Server and Visual Studio running on it.  I’ll be doing some live coding and database querying and want a nice experience for the attendees.

My options were procure a Windows laptop for the presentation, dual boot my existing laptop, or see if I could run my example natively on my Mac.  I didn’t want to borrow a laptop and setting up dual boot and installing Windows, Visual Studio, etc sounded like a lot of work.

I knew I could run the website part of my example on my Mac thanks to .NET Core but what about SQL Server?  I could use a different database but wanted to stick with SQL Server because it’s the database most of the SQL Saturday attendees are familiar with.

Some Googling reviled that SQL Server can run on a Docker container and that Microsoft has a SQL Server Docker image.  I tried it an it worked.

First install Docker for MacOS which you can find here.  Once installed you should see a whale in the status menus at the top right.

Docker Running on Mac

Next open up a terminal and pull down the SQL Server Docker image.

$ docker pull microsoft/mssql-server-linux

Pull SQL Server Docker Image

Now run the Docker image.

$ docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password1234!' -p 1433:1433 --name SQLServerForDemo -d microsoft/mssql-server-linux:latest

Run SQL Server Docker Container

List Running Docker Images

Notice the port number and don’t forget to set the name so it’s easier to find your image.

Now you can access SQL Server via the command line but I prefer a GUI client.  Plus a GUI client would look better during the presentation.  You can’t install SQL Server Management Studio on a Mac but there other clients you can use.  My preference is DataGrip because it works well and it’s included in my JetBrains subscription.  If you use ReSharper check your subscription level and see if it’s includes DataGrip.

In DataGrip you need to add a new DataSource.

DataGrip add SQL Server Data Source

For the address you can use localhost but you need to specify the port you used when running the SQL Server Docker container.  Your password is the one you used to run the Docker image.  Also install any missing drivers if prompted.

DataGrip Setup SQL Server Data SourceNow you should be able to see your SQL Server database server in DataGrip.  You can then add new databases as needed.

DataGrip Create TestDb

Any changes you make to the database will be persisted even when you start and stop the image.

P.S. – Picked this song because Docker has a whale as it’s mascot and this video is about a whale and got a whale in the video.

And we are far from home, but we’re so happy
Far from home, all alone, but we’re so happy


This entry was posted in Software Development, Today I Learned and tagged , , , . Bookmark the permalink.