Macbook M2
Photo by Bram Van Oost on Unsplash

Introduction

Microsoft SQL Server is known as the most widely used relational database in the world, especially among enterprise organizations. Although SQL Server is typically available on the Windows-based application market, it was first supported on Linux with the release of MS SQL 2016. On Mac OS, we can enjoy the benefits of that by running Linux-based MS SQL containers in Docker Desktop.

Docker Desktop offers two fundamental types of bridge networks: the default bridge and user-defined bridge networks. In this blog post, I’ll walk you through both options, allowing you to make a well-informed choice for running MS SQL Server with Docker on your Mac.

Let’s crack on.

Prerequisites

Before we start, it’s mandatory to get Docker Desktop up and ready on your Mac.

Installing MS SQL with Default Bridge Network

Starting the Server

On ARM-based systems, we can start MS SQL Server using the Docker image azure-sql-edge as following:

docker run -d --name sqlserver \
--cap-add SYS_PTRACE \
-p '1433:1433' \
-e 'ACCEPT_EULA=1' \
-e 'MSSQL_SA_PASSWORD=YourStrongPassw0rd' \
mcr.microsoft.com/azure-sql-edge

This command maps the SQL service port inside the container to the same port on your Mac, making it accessible even from outside of Docker.

Installing a Client

I would suggest Azure Data Studio which is cross-platform supported. While specifying the connection string, note that the server points to your Mac’s IP address.

Installing MS SQL with User-Defined Network

Starting the Server

Follow these steps:

  1. Create a SQL dedicated network.

    docker network create sqlnet
    
  2. Start a SQL Server container and attach it to that network.

    docker run -d --name sqlserver \
    --cap-add SYS_PTRACE \
    --net sqlnet \
    -e 'ACCEPT_EULA=1' \
    -e 'MSSQL_SA_PASSWORD=YourStrongPassw0rd' \
    mcr.microsoft.com/azure-sql-edge
    

Installing a Client

The real advantage of the user-defined networks comes into play when containers need to communication with each other. To interact with the server, we can start an additional container using this command:

docker run  -it \
--net sqlnet \
--platform linux/amd64 \
mcr.microsoft.com/mssql-tools \
/opt/mssql-tools/bin/sqlcmd \
-S sqlserver -U sa -P YourStrongPassw0rd

Below are what we’ve done in the command:

  • Started another Docker container which acts as a client.
  • Put it to the same network as the SQL Server.
  • Logged in to the server using its container name.

Default Bridge vs. User-Defined Network

The following table summarizes the pros and cons of each network type.

Default bridge networkUser-defined bridge network
ProsWhen you start a container without specifying a network, it will be plugged into the default network bridge and it works seamlessly without having any Docker networking knowledge.Automatic DNS resolution is supported, allowing containers within the same network communicate with each other over their unique name.
ConsWe should know the IP of the SQL Server to establish the connection.Require extra work and knowledge to control and maintain.
Use casesSuitable for accessing the SQL Server outside Docker, such as from the host or another machine.Ideal when the SQL Server should be accessible from containers within the same network.

Final thoughts

Setting up MS SQL on an ARM-based Mac using Docker is a game-changer. This guide showed you how to do it step-by-step. While our main focus was on getting MS SQL up and running, the extra tips on Docker networking can come in handy. Keep experimenting, and happy coding on your Mac!