Risan Bagja

Installing SQL Server on macOS

It’s a bit inconvenience when working on a project that uses the Microsoft SQL Server while your dev machine is either Linux or macOS. I always ended up setting up and using a remote test database.

But now it’s no longer the case. October last year, SQL Server 2017 for Linux finally went into general availability. It’s container images are also available on Docker hub for us to use. That means we can finally install SQL Server on macOS!

Table of Contents

Installing Docker

First, you’re going to need Docker. If you haven’t had it installed, heads up to the Docker store website and download the community edition for Mac. Just follow the instructions, it’s super easy to install.

Once it’s installed, you’ll have a new Docker icon on your menu bar. Click this icon and make sure that Docker is already.

Docker is running
Docker is running

Running SQL Server Container Image

Once you have Docker installed and running, open the terminal and run the following command to pull the latest version of SQL Server 2017 container image from Docker hub:

$ docker pull microsoft/mssql-server-linux:2017-latest

If you want to pull another version, just replace the 2017-latest part with the desired tag. You can check all of the available tags on Docker hub. For example, if want to pull the GA (General Availability) version instead, use the following command:

$ docker pull microsoft/mssql-server-linux:2017-GA

Once the image is pulled, you can run it on a new container using the following command:

$ docker run -d -p 1433:1433 --name awesome \
  -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=P@55word' \
  microsoft/mssql-server-linux:2017-latest

To list all of the containers, run the following command:

$ docker ps -a

You should see the output similar to this:

CONTAINER ID  IMAGE                                     COMMAND                 CREATED         STATUS        PORTS                   NAMES
57e0a397b4d9  microsoft/mssql-server-linux:2017-latest  "/bin/sh -c /opt/mss…"  10 seconds ago  Up 5 seconds  0.0.0.0:1433->1433/tcp  awesome

Locate your awesome container and make sure that its STATUS column is Up. If the status is Exited, checkout the troubleshooting guide.

Handy Tips & Tools

Congratulation! 🎉 You now have Microsoft SQL Server installed on your macOS machine! Here are some common Docker commands that might come in handy for you:

# Stop the `awesome` container
$ docker stop awesome

# Start the `awesome` container
$ docker start awesome

# Forcefully remove the `awesome` container
$ docker rm -f awesome

# Remove the pulled image
$ docker rmi microsoft/mssql-server-linux:2017-latest

It’s a bit inconvenience to run the sqlcmd from within the container in order to work with the database. Luckily there are some tools that you can use for interfacing with SQL Server:

Credits: