Navigate back to the homepage

Running Microsoft SQL Server.. on a Mac!

Mark Brown
October 6th, 2020 · 1 min read

👋 Introduction

A few years ago I switched my main work machine from Windows to Mac – despite the reliance I have on SQL Server to run our application (Well, there’s also the dev-only H2 database, but even then I knew that wouldn’t fly due to some of the ‘subtle’ differences).

f

At the time I had no idea what containerisation was – so i’d thought my only option was to run my database in a Windows VM or use Wine to run SQL Server natively. Thankfully I was then introduced to docker – it allowed me to run my database on the Mac OS side (well, technically within a Linux container), rather than faffing around with a Windows VM, now I can gladly say I only need a Windows VM for one task, and that’s because i’m yet to find a replacement a powerful as SSMS for comparing query plans.

🐳 Installing Docker

Installation of docker is pretty straightforward, just follow the instructions on the docker site. Once complete, the Docker ‘whale’ icon should be visible in the Mac OS menu bar.

f

🏃‍♂️ Pull & Run the SQL Server Docker image

In a terminal window of your choice (I recommend iTerm2) – run the following;

Pull the container image from Docker Hub

1sudo docker pull microsoft/mssql-server-linux:2017-latest

Run the image

1sudo docker run \
2 -e "ACCEPT_EULA=Y" \
3 -e "SA_PASSWORD=<YourStrong@Passw0rd>" \
4 -p 1433:1433 \
5 --name sql1 \
6 -d microsoft/mssql-server-linux:2017-latest
ParameterDescription
-e “ACCEPT_EULA=Y”Set ACCEPT_EULA to confirm you accept the end user licensing agreement, this is required to start the image.
-e “SA_PASSWORD=<YourStrong@Passw0rd>”Specify your own strong password, again this is required to start the image.
-p 1433:1433Map a port number on the host environment (your machine) to with a TCP port on the container (second number)
-name sql1A name for the container. If not specified, a random one will be generated.
-volume /Users/mark/DockerShare:/HostShare/Map a shared folder from the Host OS to the docker container (Very useful for transferring database backups!)

Connect to Docker SQL Server with a SQL Editor

So, you may have guessed by now – but not only will SQL Server not work on Mac OS, but neither will SQL Server Management Studio! But fear not, Microsoft still has our backs – I have been using Azure Data Studio to connect to and manage my SQL Server container, and have found it can do (almost) everything I need. To connect, simply input the login credentials specified when running the container.

f

💅 Summary

As you can see – it’s very simple to get an instance of SQL Server running in Docker. Within a few short minutes, you can have the Server up and running – and likewise – replace an existing SQL Server image (if you’re anything like me, replacing the image will be pretty common if you bloat it with unused database backups!).

More articles from Mark Brown

Introduction to Indexes, and the Primary Key

Database indexing is a development task. The most important information for indexing is not the storage system, or the configuration of the server - but instead how the application queries the data. This knowledge is not easily obtained from DBAs or external consultants - so it's on us, the developers.

August 18th, 2021 · 4 min read

Fixing the N+1 query problem

In an earlier blog post, I touched upon the cardinal sin of performance issues - N+1 queries. In this blog post I am going to explain through a few examples what the N+1 query problem is, and also suggest how to fix each in your application code.

April 18th, 2021 · 2 min read
© 2020–2021 Mark Brown
Link to $https://twitter.com/marktjbrownLink to $https://github.com/mtjbLink to $https://instagram.com/marktjbrownLink to $https://www.linkedin.com/in/mark-brown-9952b4a8/