Running SQL Server on macOS Silicon natively using Docker

Running SQL Server on macOS Silicon natively 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 Docker docs.
  • 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.
The screenshot is displaying the docker settings menu which has a set of options, the two options listed above are checked.

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 are 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:

docker 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:

# make sure you set your own password
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" \
   -p 2022:1433 --name sql2022 --hostname sql2022 \
   -p linux/amd64 \
   -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:

# make sure you set your own password
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" \
   -p 2019:1433 --name sql2019 --hostname sql2019 \
   -p linux/amd64 \
   -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:

-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 screenshot shows the connection panel in Azure Data Studio with localhost set and a user name and password set.

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 screenshot shows Azure Data Studio connected to the database.

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