SQL Server Setup on Mac with Docker: A Step-by-Step Guide

A straightforward guide to setting up SQL Server on Mac using Docker. From installation to running a SQL Server container, this article provides easy-to-follow steps tailored for developers and database enthusiasts on macOS

SQL Server Setup on Mac with Docker: A Step-by-Step Guide

Setting up SQL Server on a Mac using Docker is a practical solution for developers who need to run SQL Server databases on macOS, where SQL Server is not natively supported. Docker provides a way to run SQL Server in a containerized environment, making it compatible with macOS. Here’s a detailed guide on how to set up SQL Server on a Mac using Docker.

Prerequisites

Docker Desktop for Mac: Install Docker Desktop for Mac from the Docker website. Docker uses virtualization to run SQL Server, so your Mac must support virtualization.

1

 

A detailed blog on How to Install Docker and Introduction to Docker

Pull the SQL Server Docker Image

  • Open the Terminal on your Mac.

Pull the latest SQL Server Docker image by running the command:

Bash
docker pull mcr.microsoft.com/mssql/server:2022-latest

This command downloads the latest SQL Server image from Microsoft’s container registry.

Run the SQL Server container

Run the SQL Server container using the following command:

Bash
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433 --name sql_server -d mcr.microsoft.com/mssql/server:2022-latest
  • Replace <YourStrong!Passw0rd> with a strong password. The SA_PASSWORD environment variable sets the database system administrator password.

  • The -p 1433:1433 option maps the default SQL Server port to the same port on your Mac, allowing you to connect to the database server locally.

  • –name sql_server names your container for easier reference.

The -d option runs the container in detached mode, meaning it runs in the background.

2

 

To run an AMD64 architecture-based Docker image (like SQL Server) on an ARM64 architecture system (like newer Macs with Apple Silicon), you might encounter a warning about the architecture mismatch. Here’s a concise guide to address this:

Warning Message You may see a warning as shown in image and below code.

Bash
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

4

 

This occurs because the SQL Server image is for AMD64, but your Mac is ARM64.

Solution

Include Platform in Command: To avoid this warning and ensure compatibility, add –platform linux/amd64 to your docker run command:

Bash
docker run --platform linux/amd64 -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourPassword' -p 1433:1433 --name sql_server -d mcr.microsoft.com/mssql/server:2022-latest

Use Rosetta Emulation: Docker will use Rosetta emulation to run the AMD64 image on ARM64. This should work fine for development purposes with minimal performance impact.

Install Rosetta (if not installed)

If you haven’t installed Rosetta 2, which is required for emulation, run:

Bash
softwareupdate --install-rosetta

Rosetta 2 enables your ARM64 Mac to run applications built for AMD64.

Verify the Container is Running

Check that the SQL Server container is running by executing:

Bash
docker ps
  • You should see your SQL Server container listed.

5

 

Connect to SQL Server:

Using Azure Data Studio:

  1. Open Azure Data Studio: Launch the application from your Applications folder.

  2. Add a New Connection: Click on the “New Connection” icon.

  3. Connection Details:

    • Server: Enter localhost if SQL Server is running locally on the default port.
    • Authentication Type: Choose “SQL Login”.
    • User Name: Enter sa.
    • Password: Enter the password you specified when you ran the SQL Server Docker container (YourStrong!Passw0rd).
  4. Connect: Click on the “Connect” button.

6

 

Using a SQL Server Management Studio (SSMS):

If you want to use SQL Server Management Studio (SSMS) on a Mac, you’ll need to set up a Windows virtual machine (VM) because SSMS is not natively supported on macOS. Here’s how to do it:

Set Up a Windows Virtual Machine on Mac:

  • Choose a Virtualization Software: Pick a virtualization tool like Parallels Desktop, VMware Fusion, or VirtualBox. Each has its pros and cons, so choose based on your preference and requirements.

Install SQL Server Management Studio (SSMS) in the VM:

  • Download SSMS: Once Windows is set up, download SSMS from the official Microsoft website.

  • Install SSMS: Run the installer and follow the prompts to install SSMS on the Windows VM.

Connect SSMS to SQL Server on Docker

  • Find Mac’s IP Address: On your Mac, find your IP address. You can do this by going to System Preferences > Network.

  • Configure SQL Server Container: Ensure your SQL Server Docker container allows connections from other hosts. You might need to adjust the docker run command to bind SQL Server to a public IP or 0.0.0.0.

  • Open SSMS on the VM: Launch SSMS in your Windows VM.

  • Connect to SQL Server:

    • Server Name: Enter your Mac’s IP address and the SQL Server port, e.g., 192.168.x.x.
    • Authentication: Use “SQL Server Authentication”.
    • Login: The default is sa.
    • Password: The password you set for the SQL Server Docker container.
    • Test Connection: Try connecting to the SQL Server. If it doesn’t connect, check the firewall settings on both the Mac and the Windows VM.

7

 

Manage the SQL Server Container

  • Start the container: docker start sql_server
  • Stop the container: docker stop sql_server
  • Remove the container: docker rm sql_server