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).
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.
🏃♂️ 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
|Set ACCEPT_EULA to confirm you accept the end user licensing agreement, this is required to start the image.|
|Specify your own strong password, again this is required to start the image.|
|Map a port number on the host environment (your machine) to with a TCP port on the container (second number)|
|A name for the container. If not specified, a random one will be generated.|
|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.
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!).