I have just started working on a new project, and the Microsoft SQL Server is being used for the project. But I am using Mac as my primary development machine at this moment, and I don’t want to switch to Windows now, just for using the SQL server.
Docker is here to rescue you.
SQL Server image is available in the docker hub; you can check the docker image details at https://hub.docker.com/_/microsoft-mssql-server.
After finding the SQL Server docker image, the second concern was, which GUI client to use for accessing SQL Server, as SQL Server Management Studio(SSMS) does not work on mac. After researching for a few minutes, I have found the easiest option. Azure Data Studio will solve my problem here.
Here is the easiest config and process that you can use for SQL Server on Docker and Azure Data Studio.
Run SQL Server Docker Container
I have kept the configuration as simple as possible. If you want to use any specific version of SQL Server, check the available options from https://hub.docker.com/_/microsoft-mssql-server.
Run Container
Use the following command to run SQL Server docker container-
docker run u002du002dname sqlserver -p 1433:1433 -e SA_PASSWORD=some2Complex7Password -e ACCEPT_EULA=Y -d mcr.microsoft.com/mssql/server
ShellScriptLet’s check the details of the provided options for “docker run” –
Argument | Description |
---|---|
–name sqlserver | Name of the container. After creation, the container will be named “sqlserver” in this case. |
-p 1433:1433 | This is config for port. This option means exposing port “1433” of the docker container to port “1433” of the host machine. As we know the SQL server will run on port “1433” of the container. So we are exposing it to the host machine, so that we can access it from the host machine. |
-e SA_PASSWORD=some2Complex7Password | “-e” is for the environment variable. Here we are setting value for “SA_PASSWORD” which is the password for the “sa” user. |
-e ACCEPT_EULA=Y | This environment var is set to confirm the acceptance of the enduser license of SQL Server. |
-d | This is for running the container in detached mode. |
mcr.microsoft.com/mssql/server | Docker image name |
Config using Docker Compose
If you want to run it using docker-compose, then here is the docker-compose.yml file for SQL Server.
version: "3.9"
services:
sqlserver:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "some2Complex7Password"
ACCEPT_EULA: "Y"
ports:
- "1433:1433"
YAMLIn the configuration, set the password in the environment value SA_PASSWORD and in the ports section, you can set the port you want to expose the service to. I have kept the default port 1433.
Use the following command to run –
docker-compose up
ShellScriptRun your Docker container and then config Azure data studio following the instructions below.
Azure data studio configuration
Download Azure Data Studio from https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15 . Go to add a new connection, and you will see a form like below.
- Connection type: Select “Microsoft SQL Server” from the dropdown.
- Server: enter “localhost,1433” in the field. Make sure to enter the port which you have in the docker configuration.
- Authentication type: Select “SQL login” from the dropdown.
- User name: enter “sa” in the field as the user name.
- Password: enter the password that you set in the docker config file. In my case, it is some2Complex7Password.
- Remember Password: check this checkbox.
WARNING
There is a comma(‘,’) between the localhost and the port number. So use a comma(‘,’) there, do not use a colon(‘:’).
I have kept all other fields to the default value.
Click on Connect button, and you should be connected to the SQL server. You should see a screen like the below.
Azure data studio does not have all the options of SQL Server Management Studio(SSMS), but it will get the job done.
That’s it, done.