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
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.
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.
A detailed blog on How to Install Docker and Introduction to Docker
Pull the latest SQL Server Docker image by running the command:
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 using the following command:
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.
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.
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
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:
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:
softwareupdate --install-rosetta
Rosetta 2 enables your ARM64 Mac to run applications built for AMD64.
Check that the SQL Server container is running by executing:
docker ps
Open Azure Data Studio: Launch the application from your Applications folder.
Add a New Connection: Click on the “New Connection” icon.
Connection Details:
Connect: Click on the “Connect” button.
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:
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.
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: