DEV Community

korey 🇳🇬
korey 🇳🇬

Posted on

HOW TO SETUP MSSQL ON MAC/LINUX OS USING DOCKER AND AZURE DATA STUDIO

Ensure you have docker setup on your machine. Follow this link to setup docker on your machine docs.

Pull the mssql ubuntu image from the docker hub.

sudo docker pull mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04

After that then enter the following command

sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong@Passw0rd>" \
-p 1433:1433 --name sql223 \
-d mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04

Ensure you replace <YourStrong@Passw0rd> with your password

-p indicates your port
--name specifies the name of your container

Run the command below to view all containers currently running on your machine.

sudo docker ps -a

Alt Text

The GUI tool we'll be using is Azure Data Studio

Follow the link and download the azure data studio.

currently, these are our details.
Password: This is what we declared in SA_PASSWORD as earlier.
Username: this value is sa
Server: localhost

Then fill out these details in Azure data studio.

Alt Text

Lastly, since we might want to create a new database in the azure data studio
Enter the following in the new Query section of the dashboard.

IF NOT EXISTS (
   SELECT name
   FROM sys.databases
   WHERE name = N'DemoDB'
)
CREATE DATABASE [DemoDB]
GO
Enter fullscreen mode Exit fullscreen mode

Alt Text

The above command creates a database called DemoDB. you can connect to this database and run various actions like migrations.

To connect to the DemoDB database we created, below is a typical connection string.

      String connectionString = @"
      Server=127.0.0.1;
      Database=DemoDB;
      User Id=sa;
      Password=yourPassword
   ";
Enter fullscreen mode Exit fullscreen mode

Discussion (0)