How to Install SQL Server and the Stack Overflow Database on a Mac

To follow along, you’ll need:

  • An Apple Mac with an Apple Silicon processor (M1, M2, etc – not an Intel or AMD CPU)
  • Azure Data Studio
  • Docker Desktop 4.16.1 or newer
  • An Internet connection

In Docker Desktop, go into Settings, Features in Development, and check the box for “Use Rosetta.” That’s the new 4.16 feature that allows you to run Intel-focused apps like Microsoft SQL Server on Apple Silicon.

1. Download & Run the SQL Server Container

We’ll follow the instructions from Microsoft’s documentation, but I’m going to abbreviate ’em here to keep ’em simple. Open Terminal and get the latest SQL Server 2022 container. You can run the below command in any folder – the file isn’t copied into your current folder.

That’ll download the ~500MB container, which takes a minute or two depending on your Internet connection. Next, start the container:

Don’t use an exclamation point in your password – that can cause problems with the rest of the script. (Frankly, to keep things simple, I would just stick with upper & lower case letters plus numbers.)

In the above example, the container’s name will be sql1. If you decide to get fancy and change that, remember the name – you’ll need it later.

You’ll get an error about the platform – that’s okay, ignore it. Docker Desktop will show the container as running:

And in less than a minute, you can connect to it from Azure Data Studio. Open ADS and start a new connection:

  • Server name: localhost
  • Port: 1433
  • Username: sa
  • Password: the one you picked above

With any luck, you’ll get a connection and be able to start running queries. To have fun, we’re going to want a sample database.

2. Download & Restore the Stack Overflow Database

Again, I’m going to abbreviate and change Microsoft’s documentation to keep things simple. Open Terminal and go into a folder where you’d like to keep the backup files. In my user folder, I have a folder called LocalOnly where I keep stuff that doesn’t need to be backed up, and I have Time Machine set to exclude that folder from my backups.

If you don’t have a folder like that, you can just go into your Downloads folder:

Download the Stack Overflow Mini database, a small ~1GB version stored on Github:

Make a backups folder inside your Docker container – note that if you changed the container name from sql1 to something else in the earlier steps, you’ll need to change it here as well:

Copy the backup file into your container:

In Azure Data Studio, restore the database:

Presto – you now have the Stack Overflow database locally.

3. Stop & Start the Docker Container

When you want to stop it, go to a Terminal prompt and type:

Because you’re exceedingly smart and almost sober, you can probably guess the matching command:

And yes, the database will still be there after you stop & start it.

For Mac Users, This is a Godsend.

Because this just works, at least well enough to deal with development, blogging, demoing, presenting, etc. For those of us who’ve switched over to Apple Silicon processors, this is fantastic. I love that I can work on the First Responder Kit without having to fire up a Windows VM.

This isn’t for production use, obviously, and it’s not supported in any official way. In this post, I didn’t touch on security, firewalls, SQL Agent, other versions of SQL Server, performance tuning, memory management, or anything like that, nor do I intend to get involved with any of that in Docker anyway.

This particular combination of technologies (plain Docker running SQL Server for Linux on a Mac with Apple Silicon processors) is brand spankin’ new as of last week, so there isn’t anything out on the web in the way of troubleshooting. However, if you want to learn more about the two components that are probably the most new to you (Docker and SQL Server for Linux), subscribe to Anthony Nocentino of He’s the go-to person for SQL Server on containers & Linux. He’s got several Pluralsight courses on these, too.

Previous Post
[Video] Office Hours: Bad Hair Edition
Next Post
[Video] Office Hours: Back Live on Twitch Again

6 Comments. Leave new

  • Works a treat 🙂

  • Hi Brent

    I use something like this normally after the cp of the files to the container. I don’t know if you agree.

    $crd = get-credential
    $fileStructure = New-Object System.Collections.Specialized.StringCollection
    Mount-DbaDatabase -SqlInstance mysqlserver -Database StackOverflow2013 -FileStructure $fileStructure -SqlCredential $crd

    Set-DbaDbOwner -SqlInstance mysqlserver -SqlCredential $crd

    • No, I’ve always used restores rather than keeping full-size copies of databases around.

      • Oh, sorry I didn’t know that. When using restore I do to this make my life easier.
        This one will be more the way you say.
        $crd = get-credential
        Restore-DbaDatabase -SqlInstance mysqlserver -Path /var/opt/mssql/backup/StackOverflow.bak -DestinationDataDirectory /var/opt/mssql/data -DestinationLogDirectory /var/opt/mssql/data -SqlCredential $crd
        Set-DbaDbOwner -SqlInstance mysqlserver -SqlCredential $crd

        • OK, cool, yeah, that’s an alternative to what I’m doing in the post.

          It doesn’t really add value for me personally because the rest of the workflow doesn’t involve PowerShell, but thanks!

  • If you get the error “/opt/mssql/bin/ line 4: [: : integer expression expected”. then go back and read the post again. You (I) forgot to enable Rosetta.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.