Geek Culture
Published in

Geek Culture

Docker Express: Running a Local SQL Server on Your M1 Mac

About 2 years ago, I wrote on how to run SQL Express in a Docker container using the Microsoft SQL Server for Linux Docker image.

Now, I find myself in need for the same on my M1 Mac. The original SQL Server for Linux image has not yet been ported to the ARM64 architecture. However, I found that there’s a new database technology, targeted for AI named Azure SQL Edge. This database has been Dockerised and ported to ARM64 and thus can run on Docker for M1 on your Mac.

TL;RD; This is how to run a Docker SQL instance on M1:

docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=MyPass@word" -e "MSSQL_PID=Developer" -e "MSSQL_USER=SA" -p 1433:1433 -d --name=sql mcr.microsoft.com/azure-sql-edge

Docker for M1

Docker for M1 has come a long way since late 2020, the Docker team’s effort shines in the latest RC version for ARM64, which can be found here. You will need to have this latest version (or later) installed to run the SQL container successfully. After installation, run the script mentioned above.

Connecting via Azure Data Studio

To connect via Azure Data Studio, you will need to put 127.0.0.1 as server, we’re already hosting the Docker container on port 1433, which is the default port for SQL. Use SQL Login and set the user to sa. Lastly, set the password you chose, which was MyPass@word from the example above.

Hit Connect and see if that works! If you have any issues connecting, maybe check to see if the container is actually running:

docker ps

If not, try starting it manually:

docker run sql

Creating a database

I recommend not to use the master database and simply just create your own, run the following in a New Query window in Azure Data Studio:

USE masterGOIF NOT EXISTS (SELECT [name]FROM sys.databasesWHERE [name] = N'TestDb')CREATE DATABASE TestDbGO

This script will create a database named TestDb, if it doesn’t exist already.

After running this script, you should see that new TestDb in the list of databases:

Be sure to select the correct database in the dropdown when running any query from now on!

Inserting data

Now let us put this to the test and insert some data. The script below will create a table, insert one record and select that record from the newly created table:

CREATE TABLE MyDto(Number INT,Text NVARCHAR(255))GOINSERT INTO MyDto VALUES (1, 'This is from my M1 Mac!')GOSELECT * FROM MyDto

That’s it! We now have a functional SQL Docker container on Apple Silicon!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store