Setting up SQL Server in macOS using Docker

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


Related Articles & Tools

Leave your thoughts...

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