January 13th, 2023

Development with SQL in containers on macOS

Drew Skwiers-Koballa
Senior Program Manager

There are a bunch of tools available for developing with SQL on macOS, including the mssql extension for VS Code and the standalone yet-comfortably-familiar Azure Data Studio. As a developer, you might have heard about the Azure SQL Database emulator and you’ve most certainly heard about deploying SQL in containers. Most recently, a new option for running SQL containers locally on your arm64 (M1/M2) Mac became available and it makes running full SQL Server images easier than ever.

In the v4.16 release of Docker Desktop, support for using Rosetta for emulation of x86/amd64 images was introduced as a beta feature, enabling improved performance and stability for running container images built for x86/amd64 on macOS 13 (Ventura).

Run SQL Server 2022 on macOS

Once you’ve enabled the new option under Settings in the “Features in development” pane, your will restart the local container runtime to apply the changes.

 

Docker Desktop settings pane, last option is enabled for "Use Rosetta for x86/amd64 emulation on Apple Silicon"

From here on, we can follow the usual steps to pull a container image and run it:

docker pull mcr.microsoft.com/mssql/server:2022-latest
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" \
   -p 1433:1433 --name sql2022 --hostname sql2022 \
   -d \
   mcr.microsoft.com/mssql/server:2022-latest

When you run the docker run command for an amd64 image on a workstation with arm64, you will see a brief warning about the image architecture and the container id on the following line.

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

If you’d prefer not to receive the warning message, you can include –platform linux/amd64 in the docker run command.  The informational warning alerts you to the emulation that will occur to run the image in that environment.

With Rosetta emulation for amd64 enabled, the SQL Server container will generally run with an indiscernible performance impact due to the emulation of amd64 binaries for arm64 and is suitable for development purposes.  The SQL instance is now available to connect locally, whether from a tool such as Azure Data Studio or from an application being developed and run locally.

Docker Desktop application interface showing list of running containers with SQL 2022 at top of list

Note: If you have not installed Rosetta 2 on your machine, you may need to run this command:

softwareupdate --install-rosetta

SQL container customization

We saw above an example command to pull the free Developer edition of SQL Server in a container and run it locally on port 1433.  SQL containers can be customized with changes to the docker run command or with a Dockerfile for further configuration. Some popular options are:

  • change the host port from 1433 to another port with -p <host port>:1433
  • store SQL data persistently with -v <host directory>:/var/opt/mssql

Comparison with arm64 Azure SQL Edge

The Azure SQL Database emulator offers 2 image options, Lite and Full, where the Full version is based on SQL Server container images while the Lite version is based on Azure SQL Edge container images.  While the Lite (Azure SQL Edge) image offers a smaller image size, it also introduces feature limitations including a lack of spatial data types and hierarchyid data type.

Azure SQL Edge also offers an arm64 image, which that runs without the host emulation layer that may show a performance impact under some workloads. For the perspective of a development environment, I’d like to offer a rudimentary comparison of the performance of Azure SQL Edge vs SQL Server 2022 running on an M1 Mac:

split screen of terminal with sqlpackage import commands on both sides
SqlPackage import comparison

On the left is a SqlPackage import of an AdventureWorks bacpac (388KB) to an arm64 Azure SQL Edge container and on the right is the same SqlPackage import operation to a SQL 2022 container running with Rosetta emulation. The Azure SQL Edge import took a fraction of a second longer than the SQL 2022 import, both of which completed in under 6 seconds.  In this process, I’ve imported the database objects (tables, stored procs, indexes) as well as the data for a small sample database.

Get started with SQL containers on macOS

Author

Drew Skwiers-Koballa
Senior Program Manager

Drew Skwiers-Koballa is a Senior Program Manager for SQL tools and experiences at Microsoft and an open source advocate. He spent nearly a decade as a database administrator and developer, building several extensions for Azure Data Studio prior to joining Microsoft.

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • Tony Pitman

    I have the latest version of Docker for Apple Silicon. When I go to settings I do not see that experimental option. Is there something else I have to do? I am signed in.

  • Joe Chang

    are there plans for SQL Server to detect and utilize P and E cores? this would apply to both Apple M1 and Intel Alder Lake/Raptor Lake processors.
    Right now, SQL Server sees Alder Lake 8P+8E with 24 threads as 12 cores. There are performance anomalies depending on which core is used. creating two resource groups, one using the P cores, and the other using the E-cores would be ok for me.