Setting Up SQL Server on Mac using Docker
date
Jul 1, 2023
slug
1
status
Published
tags
SQL Server
Docker
ASP.NET
summary
type
Post
Introduction:
In my recent exploration of ASP.NET development, I encountered an error while attempting to establish a local SQL Server. To address this issue, I have documented the troubleshooting steps and the solution for reference.
Please note that I am currently in the early stages of learning, so if there are any inaccuracies, please kindly point them out. Thank you!
When developing ASP.NET applications on a Mac, Microsoft SQL Server Management Studio is not available, and Azure Data Studio is recommended instead. However, before connecting to SQL Server in Azure Data Studio, it is necessary to set up SQL Server. One way to achieve this on a Mac is by using Docker. In this blog post, we will explore the steps to successfully create a SQL Server container using Docker on a Mac.
Step 1: Install Docker
Before getting started, make sure Docker is installed on your Mac. Docker provides a platform for running and managing containers. You can download and install Docker from the official Docker website.
Next, pull the SQL Server container image from the official Docker repository. Open a terminal window and run the following command:
This command downloads the SQL Server container image to your local machine.
Step 3: Create and Run the SQL Server Container (Official Method)
Now, let's try the official method to create and run the SQL Server container using Docker. Execute the following command in the terminal:
In this command, you specify environment variables such as the EULA acceptance and the SA password. The port 1433 is mapped to the host machine's port 1433, allowing connections to the SQL Server instance. The container is given a name of "sql" and a hostname of "sql".
Step 4: Verify the SQL Server Container
To verify that the SQL Server container is running successfully, execute the following command:
This command lists all containers on your machine. Look for the container named "sql" in the output. If the STATUS column shows "Up", it means the SQL Server container is running.
Step 5: Connect to SQL Server
Once the SQL Server container is up and running, you can connect to it using Azure Data Studio or any other SQL Server client tool. Provide the necessary connection details such as the server address (localhost or the IP address of your machine), port (1433), SA username, and SA password.

Troubleshooting: Exited Status and Alternative Method
If the SQL Server container shows an "Exited" status using the official method, you can try an alternative method using the Azure SQL Edge container. Run the following command in the terminal:
This command creates and runs the Azure SQL Edge container, which can be used as an alternative to the official SQL Server container.

Conclusion:
By following the steps outlined in this blog post, you can successfully set up SQL Server on a Mac using Docker. If you encounter any issues with the official method, you have the option to try the Azure SQL Edge container as an alternative. This provides flexibility in choosing the method that works best for your development environment. Enjoy coding with SQL Server!
Please find below a detailed video tutorial demonstrating the second method.
Additionally, I would like to provide the official Microsoft documentation for reference: Docker: Install containers for SQL Server on Linux - SQL Server"
"Furthermore, I have included a detailed video tutorial demonstrating the usage of the second method."

中文版:
Mac上通过Docker里创建SQL Server:
Mac上做ASP.NET开发时Database Setup无法使用Microsoft SQL Server Management Studio,而是需要使用Azure Data Studio。但是启动Azure Data Studio新建连接时不提前设置好 SQL Server是会报错的。
而创建SQL Server,Mac上需要在Docker里创建。尝试用官方提供的方式建立,但一直报错:SQL Server 容器显示为 "Exited" 状态。后面找到一个台湾人写的教程,没想到竟然真成功了。
运行Docker后在在终端中输入以下命令:
更详细的操作也可以参看以下视频: