MS SQL Server on Mac with Docker
Follow this guide to install MS SQL Server on a Mac machine. You pull SQL Server 2019 container image from Docker and connect to the database with sqlcmd
utility.
MS SQL Server and
sqlcmd
utility is preinstalled in this container.
Prerequisite
- Mac OS
- Docker Desktop for Mac.
- Refer the common Prerequisite section.
- Start the Docker engine on your Mac machine and log in with your DockerHub credentials.
Pull and run the 2019 container image
- Pull the SQL Server 2019 Linux container image from Microsoft Container Registry.
sudo docker pull mcr.microsoft.com/mssql/server:2019-latest
- Next, run the container image
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong@Passw0rd>" \-p 1433:1433 --name mssql -h mssql \-d mcr.microsoft.com/mssql/server:2019-latest
Note that on modern Macs with Apple Silicon based processors you will likely get a message from Docker along the lines of:
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
To circumvent this you can navigate to Settings in your Docker Desktop and click Features in Development and check "Use Rosetta for x86/amd64 emulation on Apple Silicon.
Docker will restart and your containers should be running properly.
- To view your Docker containers, use the
docker ps
command.
docker ps
Your SQL Server container is successful if you see the status of 'Up' in the STATUS column.
Connect to SQL Server
- Start a bash shell inside the container
sudo docker exec -it mssql "bash"
The command takes you to the container prompt as shown in the screenshot above.
- Next, connect locally with the database using the
sqlcmd
utility
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "<YourStrong@Passw0rd>"
If successful, you should get to a sqlcmd
command prompt: 1>
.
You can enter the T-SQL statements on this prompt.
To exit the sqlcmd
utility, type quit
.
Manage Container
Type exit
to leave the container and return to Mac prompt.
To remove your docker container and image, follow the steps in sequence:
- First stop the container -
docker stop mssql
- Remove the stopped container:
- To see all the stopped containers:
docker ps -a
- Now stop the container with its name:
docker rm mssql
- To see all the stopped containers:
- Remove the image
- Get a list of images:
docker images
. Identify and copy the mssql value from the<IMAGE ID>
column. docker rmi <Image_Id>
.
- Get a list of images:
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs