Install and configure Microsoft SQL Server on macOS using Docker, sqlcmd, and a sample ecommerce schema.
Many macOS developers need to prototype against Microsoft SQL Server without maintaining a Windows VM. Docker lets you spin up an isolated, disposable SQL Server instance that behaves identically to production, enabling local testing, migration development, and cross-database comparisons with PostgreSQL.
Install Docker Desktop for Mac (v4.0+), the Microsoft ODBC driver, and the cross-platform sqlcmd CLI. Homebrew installs these quickly: brew install --cask docker
and brew install mssql-tools
.
Use the official image. The command sets the SA password, exposes port 1433, and names the container for easy reference:
docker run -e 'ACCEPT_EULA=Y' \
-e 'MSSQL_SA_PASSWORD=Str0ng_P@ss!' \
-p 1433:1433 --name sqlserver \
-d mcr.microsoft.com/mssql/server:2022-latest
Run docker ps
to confirm the container’s status. Then connect with sqlcmd -S localhost -U sa -P 'Str0ng_P@ss!'
. A 1>
prompt indicates success.
Inside sqlcmd, execute the batch below to mimic a production schema:
CREATE DATABASE Ecommerce;
.
GO
USE Ecommerce;
GO
CREATE TABLE Customers (
id INT IDENTITY(1,1) PRIMARY KEY,
name NVARCHAR(100),
email NVARCHAR(255),
created_at DATETIME DEFAULT GETDATE()
);
CREATE TABLE Products(
id INT IDENTITY(1,1) PRIMARY KEY,
name NVARCHAR(100),
price DECIMAL(10,2),
stock INT
);
CREATE TABLE Orders(
id INT IDENTITY(1,1) PRIMARY KEY,
customer_id INT REFERENCES Customers(id),
order_date DATETIME DEFAULT GETDATE(),
total_amount DECIMAL(10,2)
);
CREATE TABLE OrderItems(
id INT IDENTITY(1,1) PRIMARY KEY,
order_id INT REFERENCES Orders(id),
product_id INT REFERENCES Products(id),
quantity INT
);
Mount a local volume when starting the container to keep database files: -v ~/mssql/data:/var/opt/mssql
. Restart with docker start sqlserver
to reuse the same data directory.
Add --restart unless-stopped
to docker run
so the service starts with Docker. Use docker stop sqlserver
when resources are tight.
Use strong SA passwords, restrict the exposed port to localhost, and reset containers before sharing screenshots or logs. Build schema migrations with tools like Flyway and check them against both SQL Server and PostgreSQL to catch dialect issues early.
Yes. The 2022 image ships with an ARM64 variant that Docker Desktop automatically downloads for M-series chips.
Aqua Data Studio, Azure Data Studio, DBeaver, and Galaxy all connect over port 1433 using the same credentials.
Connect with sqlcmd
and run ALTER LOGIN sa WITH PASSWORD = 'N3w_Str0ng_P@ss!';
. Restart the container to apply.