Tutorial: Learn how to run Microsoft SQL Server on Mac OSX with Docker now! 💽

In this database development tutorial, we’ll cover how to run the Microsoft SQL Server database (MSSQL) on an Apple Mac laptop running Mac OSX (macOS) using Docker in several easy steps, including two tests (see step three and step four) to verify that the relational database is running properly and available in your local environment.

Step three and step four cover two optional tests that can help determine that the SQL Server database running and also available locally on your Apple Mac.

Running SQL Server on a Mac might seem to be an uncommon use case, however thanks to Docker, it’s both possible as well as straightforward.

SQL Server on Mac TOC

This guide will walk you through the process of setting up a SQL database environment on macOS, leveraging containers for efficiency and flexibility.

Docker provides a powerful solution for running Microsoft SQL Server seamlessly and without requiring a dedicated Windows machine.

This article was updated on July 2, 2025.

JDataFrame: A Simple Java DataFrame API for R Integration

The open-source JDataFrame library makes moving data from Java to R fast and simple.

Instructions regarding how to run Microsoft SQL Server in an Apple Mac

The following example was developed on a Mac laptop (MacBook Pro, specifically) however it should work on other Apple computers as well.

Tutorial Preconditions

We need the following tools for this instructional:

CTO Consulting Services

As a dedicated CTO Consultant, I provide strategies that will enhance your software development effort as well as help your software engineers deliver better products.

Step One: Pull the MS SQL Server image from DockerHub

We need to pull the Microsoft SQL Server Docker image from DockerHub and we do this using the following command:

				
					docker pull mcr.microsoft.com/mssql/server:2022-latest
				
			

We can see an example of the docker pull command output below:

Docker pull command for Microsoft SQL Server with successful output.
The Docker pull command for Microsoft SQL Server with successful output.

Step Two: Create a container from the docker image.

In the next step we create a container from the docker image using the following command:

				
					docker run --name SQLServer -e 'ACCEPT_EULA=[Y|N]' -e 'SA_PASSWORD=password-12345' -e 'MSSQL_PID=Express' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
				
			

Here’s a breakdown of each environment variable (see the article entitled Configure SQL Server settings with environment variables on Linux for more information):

ACCEPT_EULA

Confirm that we accept the end user license agreement by using the value “Y” for “yes”.

SA_PASSWORD

The Microsoft SQLServer system administrator account password.

MSSQL_PID

The Microsoft SQL Server process identifier — this is limited to Developer, Express, Standard, Enterprise, or a unique product key used to activate a specific version.

Since we’re using the Express edition in this example, “Express” will be the value we use here.

We can see an example of the docker run command output below.

The Docker run command for MS SQL Server on Mac OS.
Microsoft SQL Server Docker Run Command

Once the Docker container is running we can check that the database is available.

The following two tests are optional.

Step Three (optional): Test that the Microsoft SQL Server database is running.

We can test that the database is running by getting command line access to the Docker container and then running a simple SQL query — we demonstrate how to execute this test in two steps here.

Obtain command line access to the Docker container.

In the first step, indicated by the red pointer, we obtain command line access to the Docker container.

				
					docker exec -it [your container id here] /bin/sh  
				
			

Execute a SQL command that returns the current date and time

In the second step, indicated by the blue pointer, we execute a SQL command that returns the current date and time.

				
					/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'password-12345' -Q "SELECT GETDATE() AS currentDateTime"
				
			

Successful test result example

A successful test result should look something like what we have in the image below.

Connect to Microsoft SQL Server via sqlcmd in Docker: The red pointer points to the command "docker exec -it dc5ece73f55f /bin/sh" and the blue pointer points to the command "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'password-12345' -Q 'SELECT GETDATE() AS currentDateTime'" which returns the current date and time.
Step Three (optional): Check that the MSSQL database is running.

In this optional test to demonstrate that the Microsoft SQL Server database is running correctly we connect to the database in Docker and then run the SQL command:

  • The red pointer points to the command “docker exec -it dc5ece73f55f /bin/sh” — this grants shell access to the running container.
  • The blue pointer points to the command “/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ‘password-12345’ -Q ‘SELECT GETDATE() AS currentDateTime’” executes the SQL query that returns the current date and time.

Step Four (optional): Test that the database is available locally.

I’m including an equivalent optional test to the one we executed in step three however in this example we use a Groovy script to execute the SQL query against the instance of the Microsoft SQLServer database running inside the Docker container.

When we create the container we map port 1433 in the container to port 1433 on localhost so this script can be used to prove that the Docker container is configured correctly in your local environment.

You can find the example Groovy script available as a gist on GitHub.

The image below demonstrates the successful execution of this Groovy example in the groovyConsole and we address what each of the pointers means in the following section.

				
					@GrabConfig(systemClassLoader=true)

@Grab(group="com.microsoft.sqlserver", module="mssql-jdbc", version="12.6.2.jre11")
import groovy.sql.Sql

def sql = Sql.newInstance("jdbc:sqlserver://localhost:1433;encrypt=false;databaseName=master", "sa", "password-12345", "com.microsoft.sqlserver.jdbc.SQLServerDriver")

println "Connected successfully."

try {
  sql.eachRow("SELECT GETDATE() AS currentDateTime") { row ->
    println "  Current date and time: ${row.currentDateTime}"
  }
} catch (Exception exception) {
  exception.printStackTrace (System.err)
} finally {
  sql.close()
}

println "Done!"

return
				
			

The image below demonstrates the successful execution of this Groovy script in the groovyConsole and we address what each of the pointers means in the following section.

It is important to note that we are NOT running this script inside the container like we did in step three — rather this is being executed from within the Apple Mac OSX operating system environment.

Step Four: In this optional test we check that Microsoft SQL Server is running and available locally. Note that the red pointer points to the Microsoft SQL Server Java driver dependency, the orange pointer points to the database connection properties and the Groovy Sql class which we can use to communicate with the database, the green pointer points to the SQL query that returns the current date and time, and the blue pointer directs our attention to the output of a successful script execution.
Step Four (optional): Check that Microsoft SQL Server is running and available locally.

In this example, the:

  • Red pointer points to the Microsoft SQL Server Java driver dependency, which is available on Maven Central.
  • Orange pointer points to the database connection properties and the Groovy Sql class which we can use to communicate with the database.
  • Green pointer points to the SQL query that returns the current date and time.
  • Blue pointer directs our attention to the output of a successful script execution.

Conclusion

At some point in the future I intend to explore if it’s possible to externalize the storage used by MSSQL by mapping a directory to the Docker container and then configuring the database via the environment variables to store data in that specific location.

Frequently Asked Questions

Can you run SQL Server on Mac?
To run Microsoft SQL Server on a Mac using Docker, install Docker Desktop and use it to set up a containerized SQL Server environment.
 
Follow the configuration steps to ensure proper setup and then verify functionality with a query or script.
author avatar
ThosPFuller
I am a software engineer based in Northern Virginia (USA) and this website focuses on content engineering, web development, Technical SEO, Search Engine Optimization (SEO).

Leave a Reply