Setting up SQL Server on macOS using Docker

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

  1. Download and install docker desktop from https://www.docker.com/products/docker-desktop.
    Installing docker in macOS
  2. Launch Docker from the Applications folder.
  3. 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.
    Provideing access ot Docker to install networking tools
  4. 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.
    Check docker version
  5. 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.
    Docker icon and menu at the menu bar

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.

  1. Now, launch the Terminal.app.
  2. Run the pull command for the latest version as specified at Docker Hub.
docker pull mcr.microsoft.com/mssql/server:2019-latest
  1. Once the pull is completed, you will get the status message saying Downloaded newer image for ….
    Pull the latest SQL Server Docker image

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.

Note

  • 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.

docker ps
Check if SQL Server docker container image is running

Or, you can check the container’s status by going to Dashboard through menu bar >> Docker icon >> Dashboard.

Setting up SQL Server in macOS using Docker

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.

  1. Launch Azure Data Studio.
  2. Press the New connections icon next to the Servers under Connections panel to open the Connection Details panel.
  3. Enter localhost for Server, sa for user name and the password you have specified in the Run command earlier and press Connect button.
    Connecting SQL Server docker image with Azure Data Studio
  4. 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.
    Connected to Docker SQL Server

Video Illustration

Related Articles

Reference


5 thoughts on “Setting up SQL Server on macOS using Docker”

  1. Great tutorial. The only step that tripped me up was how I read the part about the password, “[[Your-Password]]”. I took the brackets to be part of the syntax to supply the password. Once, I realized that my password was “[[12345678]]” minus the “”, I was good to go. Thanks!

    Reply
  2. Hello, I’m having this message when I try to connect to Azure. Do you have any idea whats wrong.. thank you..

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 – Could not open a connection to SQL Server: Could not open a connection to SQL Server)

    Reply
  3. Hi Sir,

    I have followed the above procedure but in docker dashboard my sql is not running it was showing as exited. Please help me how to resolve the issue and I am unable to connect to server from Azure.

    Reply
    • Hi Nithesh,

      The SQL Server container might have stopped for some reason. Try restarting it. To restart the SQL Server container from the docker dashboard, move the mouse over the sql server name, few icons will appear to the right. One of the icons (arrow inside a circle) is the start button. Just press it to start the SQL Server again. Hope this will help.

      Reply

Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.