To follow along, you’ll need:
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.
sudo docker pull mcr.microsoft.com/mssql/server:2022-latest
That’ll download the ~500MB container, which takes a minute or two depending on your Internet connection. Next, start the container:
sudo docker run -e "ACCEPT\_EULA=Y" -e "MSSQL\_SA\_PASSWORD=<YourStrong@Passw0rd>" \ -p 1433:1433 --name sql1 --hostname sql1 \ -d \ mcr.microsoft.com/mssql/server:2022-latest
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:
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.
cd ~/LocalOnly
If you don’t have a folder like that, you can just go into your Downloads folder:
cd ~/Downloads
Download the Stack Overflow Mini database, a small ~1GB version stored on Github:
curl -L -o StackOverflowMini.bak 'https://github.com/BrentOzarULTD/Stack-Overflow-Database/releases/download/20230114/StackOverflowMini.bak'
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:
sudo docker exec -it sql1 mkdir /var/opt/mssql/backup
Copy the backup file into your container:
sudo docker cp StackOverflowMini.bak sql1:/var/opt/mssql/backup
In Azure Data Studio, restore the database:
RESTORE DATABASE StackOverflowMini FROM DISK='/var/opt/mssql/backup/StackOverflowMini.bak'WITH MOVE 'StackOverflowMini' TO '/var/opt/mssql/data/StackOverflowMini.mdf', MOVE 'StackOverflowMini\_log' TO '/var/opt/mssql/data/StackOverflowMini\_log.ldf';
Presto – you now have the Stack Overflow database locally.
docker stop sql1
Because you’re exceedingly smart and almost sober, you can probably guess the matching command:
docker start sql1
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 Nocentino.com. He’s the go-to person for SQL Server on containers & Linux. He’s got several Pluralsight courses on these, too.