Now that Docker has made every developers life easier, I’m going to walk you through a few quick steps to get Microsoft SQL Server up and running on MacOS. The first thing you need to do is install Docker on your Mac.
I chose to install Docker Desktop so that’ll be what I’ll be using for this tutorial. You can choose to install Docker Toolbox if you choose. Use the following link to determine which best fits your needs: https://docs.docker.com/docker-for-mac/docker-toolbox/
Once Docker Desktop is installed, launch it and open the settings by clicking the docker icon and selecting Preferences.
This will launch your Docker Dashboard. Once opened, clicked the Settings gear at the top right and click on Resources >> Advanced. SQL Server needs at least 3.2 GBs of memory so increase the Memory to 4 GBs and click Apply & Restart.
Download the SQL Server Image
To download the SQL Server image, open Terminal and type the following:
docker pull mcr.microsoft.com/mssql/server:2019-latest
This will download the latest SQL Server 2019 image to your mac.
Launch the SQL Server Image
From Terminal, run the following command:
docker run --name ms_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=5uper5trongPW!' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
Don’t forget to change the password to your own secure password. This command sets the name of the docker container to ms_sql_server. The user is defaulted to sa. For more configuration settings, go the MS SQL Server container hub. Once you launch the image it’ll be available in Docker Dashboard. From here you can stop the image, restart it, delete, etc.
Visual Studio Code
There are several MS SQL Server GUIs available for MacOS but I prefer to use VS Code since its my development tool of choice. To install the MS SQL extension on VS Code, click the extensions icon and type: mssql. From the search results, select SQL Server (mssql) and click Install. After the installation completes, select Reload to enable the extension. Once enabled, you’ll have a SQL Server icon on the left. Click on it and select Add Connection.
Follow the prompts, using localhost as hostname, sa as user and your password you set up when launching the SQL Server image. You should also give your connection a name to be able to identify it later. For this tutorial I named my connection TestSQL.
That’s it! You now are free to create your database, tables, etc.
If you stop and remove your container, you’ll lose all your SQL Server data. To avoid this you can create a backup of your database or you can persist your data in volume containers.
Top comments (0)