Running SQL Server on macOS silicon using Docker

Running SQL Server on macOS silicon using Docker

Table of Contents

Introduction

I use a Mac as my day to day machine and I have always had to find creative ways to run SQL Server and Power BI since they don’t natively run on macOS. I have used different methods over the years, using VMWare and Parallels at different times but in the silicon era this hasn’t always been as straightforward because the Mx chips run on ARM architecture. But now you can run SQL Server on macOS using Docker and it’s really easy to set up.

Pre-requisites

Before you can complete the step below, you need to install and configure Docker and Rosetta 2.

Install Docker and Rosetta 2

  • install Docker from here.
  • install Rosetta 2 by running softwareupdate --install-rosetta from the command line

Configure Docker

You need to set two settings in Docker, check the following options in Settings > General:

  • Use Virtualization Framework.
  • Use Rosetta for x86_64/amd64 emulation on Apple Silicon.

Update to this post…the Use Rosetta for x86_64/amd64 emulation on Apple Silicon setting is now a general setting since version 4.29.0. If you’re using a previous version, you will find it in Settings > Features in development if it’s not in there either, it’s time to update!

Pull container image

With docker running, you can pull the SQL Server 2022 container image by running the following command:

1docker pull mcr.microsoft.com/mssql/server:2022-latest

Run the container

The following command will configure a container with a few settings, then fire it up:

1# make sure you set your own password
2docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" \
3   -p 2022:1433 --name sql2022 --hostname sql2022 \
4   -p linux/amd64 \
5   -d mcr.microsoft.com/mssql/server:2022-latest 

I have set a few options here:

  • -p 2022:1433 will map the host port 2022 to the container port 1433 so I can access the server at localhost:2022
  • --name sql2022 will name the container sql2022
  • --hostname sql2022 will set the hostname to sql2022
  • -p linux/amd64 sets the platform otherwise you get a warning raised WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

Why set the port and host name? Because you can run multiple versions of SQL Server using this pattern, so I can install SQL Server 2019 on port 2019 like so:

1# make sure you set your own password
2docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" \
3   -p 2019:1433 --name sql2019 --hostname sql2019 \
4   -p linux/amd64 \
5   -d mcr.microsoft.com/mssql/server:2019-latest 

Persist storage

If you want to persist the data, you can set up a volume using the -v flag like so, but I haven’t tested this yet:

1-v <host directory>:/var/opt/mssql

Access from Azure Data Studio

From there you can work with SQL Server natively using Azure Data Studio, just connect to localhost,2022 using the sa account and the password you set:

The server

You can then run queries, create databases, and do all the things you would normally do with SQL Server! Here is a screenshot showing me connected to both SQL Server 2019 and 2022:

The server

Conclusion

And that’s it! Very simple to set up. I would need to revert to Parallels to run SSMS and I still need to do that for Power BI but it’s great to have SQL Server running natively on my Mac for quick development and testing tasks.

References

#mtfbwy



Recent Posts

Hugo Live Reload Keeps Reloading

Hugo Live Reload Keeps Reloading

  • 2024-05-18
  • 3 minutes to read

I have run into an issue from time to time where Hugo's live reload feature keeps reloading the page. This is how I fixed it.

Read More
First Steps with Mermaid in Vscode

First Steps with Mermaid in Vscode

  • 2024-05-17
  • 7 minutes to read

My blog theme supports mermaid, a visual diagram syntax, so I wanted to try it out in vscode.

Read More
T-SQL Tuesday #174 My favourite job interview question

T-SQL Tuesday #174 My favourite job interview question

  • 2024-05-14
  • 4 minutes to read

This is my 12th contribution to TSQL Tuesday, the data community blog party. Have a read, and why not join in next time!

Read More