[macOS] Running SQL Server with Docker on macOS

SQL Server cannot be installed and run on macOS, but starting from SQL Server 2017, it supports Linux, so it can be run on macOS with Docker.

Installation

Install Docker

How to install Docker on macOS, please see the official documentation [Install Docker Desktop on Mac - https://docs.docker.com/docker-for-mac/install/](https://docs.docker.com/docker-for -mac/install/).

Docker can also be installed through the brew package manager.

1
brew install --cask docker

For more information on brew, see The Missing Package Manager for macOS (or Linux) — Homebrew - https://brew.sh/.

Pull SQL Server image

Execute the following command to pull SQL Server image:

1
sudo docker pull mcr.microsoft.com/mssql/server:2017-latest

Create and run the container using SQL Server image

Execute the following command to use the mcr.microsoft.com/mssql/server:2017-latest image to create a container named sqlserver with port 1433.

1
2
3
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Passw0rd" \
-p 1433:1433 --rm --name sqlserver \
-d mcr.microsoft.com/mssql/server:2017-latest
  • -e "ACCEPT_EULA=Y" sets the ACCEPT_EULA variable to an arbitrary value to confirm acceptance of the End User License Agreement.

  • -e "SA_PASSWORD=Passw0rd" specifies a strong password with at least 8 characters that meets SQL Server password requirements.

  • -p 1433:1433 maps a TCP port in the host environment (first value) to a TCP port in the container (second value).

  • After --rm exits the container, the container will be deleted, which is convenient for temporary testing.

  • --name sqlserver specifies a custom name for the container instead of using a randomly generated name.

For more information about SQL Server images, please refer to [Microsoft SQL Server - Ubuntu based images | Microsoft Artifact Registry - https://mcr.microsoft.com/en-us/product/mssql/server/about](https:/ /mcr.microsoft.com/en-us/product/mssql/server/about)

View container status

1
ps -e | grep sqlserver

You can check the SQL Server running log by executing the docker logs command.

1
docker logs sqlserver

Usage

Connect to SQL Server inside the container

  • Use the docker exec -it command to start an interactive `Bash Shell’ inside the running container:

    1
    docker exec -it sqlserver bash

    sqlserver is the name specified by the -–name parameter when creating the container.

  • Use sqlcmd for local connections inside the container. By default, sqlcmd is not in the path, so the full path needs to be specified.

    1
    2
    /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Passw0rd"
    1>
  • If successful, the sqlcmd command prompt 1> should be displayed.

Connect to SQL Server with visual tools such as DBeaver

How to install DBeaver on macOS, please refer to the official document Download | DBeaver Community - https://dbeaver.io/download/.

DBeaver can also be installed via the brew package manager.

1
brew install --cask dbeaver-community

SQL Server DBeaver

References

[1] Install on Mac | Docker Documentation - https://docs.docker.com/desktop/install/mac-install/

[2] Microsoft SQL Server - Ubuntu based images | Microsoft Artifact Registry - https://mcr.microsoft.com/en-us/product/mssql/server/about

[3] SQL Server 2017 on Windows and Linux | Microsoft - https://www.microsoft.com/en-us/sql-server/sql-server-2017

[4] Microsoft Data Platform | Microsoft - https://www.microsoft.com/en-us/sql-server/

[5] docker — Homebrew Formulae - https://formulae.brew.sh/cask/docker

[6] dbeaver-community — Homebrew Formulae - https://formulae.brew.sh/cask/dbeaver-community

[7] Download | DBeaver Community - https://dbeaver.io/download/

[8] DBeaver Community | Free Universal Database Tool - https://dbeaver.io/

[9] The Missing Package Manager for macOS (or Linux) — Homebrew - https://brew.sh/

[10] Install and Run SQL Server Docker Container on Mac | CloudIQ Tech - https://www.cloudiqtech.com/install-run-sql-server-docker-container-mac/