SQL Server is a powerful database option to use, but up until recently it's not been possible to use it unless you were on a Windows machine. Well, that's changed (along with many other Microsoft products). This week at work I decided to finally jump in and get SQL Server running on my Mac using Docker. Here's a quick recap of how I did this.
There were three pages that I used to get up and running. The first was on Docker Hub, on the image information page. Just follow the simple instructions there and you'll get the image pulled and the container running.
Now, if you don't need to backup an existing database to your instance, you're all set! Connect to the database with VS Code and the mssql extension, or any other database management application that runs on Mac and connects to SQL Server. In my case, though, I needed to restore a database that we were using for work so that I had that data locally. The next two steps were needed for that.
As I searched for instructions on how to do this, I came across this answer on Stack Overflow. I personally didn't use step 3 in his answer because I was connected to the database using VS Code and mssql. Basically his answer has you get the ID of the container, copy the backup file from your computer into the container, and then runs a
RESTORE DATABASE FROM FILE command in SQL Server.
For me, this wasn't quite enough to get me home, though. I hade an error where the database said it couldn't find the MDF and LDF files referenced in the backup. That's where this blog post helped out. The post says to just specify where the new MDF and LDF files should be inside the container. It was simple, and worked right away.
In the end, here's the full command I ran:
RESTORE DATABASE [MyDatabase] FROM DISK = N'/var/opt/mssql/backup.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5, MOVE 'MyDatabase' TO '/var/opt/mssql/data/MyDatabase.mdf', MOVE 'MyDatabase_log' TO '/var/opt/mssql/data/MyDatabase_log.ldf'
Again, all in all, this was an easy project to get up and running. It took a while to find the right resources, which is why I decided to put them all together in one spot, but going forward it should take no more than 20-30 minutes to get SQL Server up and running on Mac or Linux using Docker.