I am using MacBook Pro for my day-today works. In it, I have set up a Windows 10 virtual machine with SQL Server, Visual Studio and other windows only applications for my development work. Sometime, for testing simple SQL queries, I found it difficult and time consuming to launch the virtual machine and work on the SQL Server.
When looking for options to have SQL Server on macOS, Microsoft introduced SQL Server to Linux using Docker, which also supports macOS. So, I have decided to use the Docker Desktop with SQL Server container. Here are the steps I have followed for setting up SQL Server on macOS using Docker Desktop. I have referred the article Quickstart: Run SQL Server container images with Docker at Microsoft Docs and providing you the simplified steps below.
Install Docker Desktop
- Download and install docker desktop from https://www.docker.com/products/docker-desktop.
- Launch Docker from the Applications folder.
- When launching Docker for the first time, it will ask for privileged access to install its network helper tool. Press OK and provide the access by entering your mac user name and password.
- Once done, the Docker Desktop user interface with a getting started tutorial will launch. Docker is now installed successfully. To confirm, run the command docker version in Terminal.app and see the version details.
- The docker icon will be visible in the mac’s menu bar at top right. On pressing the icon, it will show the menu, and you can see the status Docker Desktop is running at the top.
Pull the SQL Server container image
Go to the Microsoft SQL Server Image page at Docker Hub to check the latest version of the SQL Server available to pull. As of this writing, it is mcr.microsoft.com/mssql/server:2019-latest.
- Now, launch the Terminal.app.
- Run the pull command for the latest version as specified at Docker Hub.
docker pull mcr.microsoft.com/mssql/server:2019-latest
- Once the pull is completed, you will get the status message saying Downloaded newer image for ….
Run the SQL Server container image
Once the container image is downloaded, you have to run the below command in Terminal.app to start the SQL Server container.
- Change [[Your-Password]] with a strong password with at least 8 characters. It should include three of these four categories: lowercase letters, uppercase letters, non-alphanumeric symbols and numbers.
- mssql_docker is the name I have given to the SQL Server. You can change it and name it as you wish.
- This command will run the SQL server in Developer edition by default. If you want to run the SQL Server in other editions, then add the environment variable MSSQL_PID to the command with the values like Express, Standard, Enterprise, EnterpriseCore or Developer.
docker run --name mssql_docker -e 'ACCEPT_EULA=Y' \ -e 'SA_PASSWORD=[[Your-Password]]' -p 1433:1433 \ -d mcr.microsoft.com/mssql/server:2019-latest
To check and confirm that the SQL Server container is running, run this command in the terminal window.
Or, you can check the container’s status by going to Dashboard through menu bar >> Docker icon >> Dashboard.
Connecting to Docker SQL Server on macOS
Use an SQL Server client tool to connect to the SQL Server on docker. Here I am using Azure Data Studio. Azure Data Studio is a cross platform tool from Microsoft which support macOS. So, it can be installed directly on your Mac. You can download and install it from https://github.com/Microsoft/azuredatastudio.
- Launch Azure Data Studio.
- Press the New connections icon next to the Servers under Connections panel to open the Connection Details panel.
- Enter localhost for Server, sa for user name and the password you have specified in the Run command earlier and press Connect button.
- The SQL Server will be connected and you can see the details in the connections panel and the main panel. You can now create your database and play around.
- Running SQL Server container images with Docker at Microsoft Docs.