MS - SQL SERVER using docker on mac m1/m2 ARM architecture

To run MS my sql we will utilise Azure Sql Edge official image on docker-hub.

If you do not have docker installed on your machine you can do so using brew with the commmand:

brew install --cask docker

Getting Docker Image:

The link to the official image on docker hub is:

https://hub.docker.com/_/microsoft-azure-sql-edge

  • Go to your terminal and run the following command to pull the official image to your machine:

docker pull mcr.microsoft.com/azure-sql-edge

Running the image:

  • Run the following to run the image you pulled and replace youtStrong(!)Password with a password of your choice.
docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge
  • Verify the running status
docker ps
  • If the container is not shown running you can check out container details using the command
docker container ls -a
  • And now run the container using the command:

    (replace <image_id> with the id of the container you just created. If the container is not created try to create it again.)

docker start <image_id>

Connect to SQL Server:

Once the container is running you can now connect to the sql server.

  • To connect to the server using the terminal execute the following command:
sudo docker exec -it mssql "bash"

Enter your sudo password. And now you have the access the sql server from here after logging in.

The username will be "sa"

The Password will be the strong password you wrote while creating the user.

After logging in with these credentials you can create more users and credentials.

Connecting using VS code:

You can also connect to this sql server using VS Code using the extension with the name SQL Server (mssql):

Once installed :

  • (1) Click on the SQL server icon in the side panel.

  • (2) Under CONNECTIONS click on add connection

  • For the server name enter "." or "localhost". Add port no 1433 if required. Press enter.

  • Enter Database name or leave empty for default. Press enter.

  • Choose 'SQL Login' in Authentication Type.

  • Enter username as 'sa'. Or you can enter a user that you created. Press enter.

  • Enter the password you set in for the user. Press Enter.

    For 'sa' user the password will be the secure password you set at the Time of creating the container.

  • Select whether or not you would like to save the password for when you connect in the future.

  • Enter The Profile Name you want. Press enter;

  • If you see a popup asking to enable trust Server Certificate then click to endable.

  • You will now be connected and will see the server and databases on the left side panel.

You can now right-click on the server and the databases and create and run queries.

To stop the running image on terminal exit the sql bash and run:

docker stop mssql

Every time that you want to connect to the SQL server again, you will only have to run the Docker image as:

docker start <image_id>

And then in vs code click on DB profile name and click connect.