Simple Guide to Run SQL Server 2017 in Docker (Linux Containers)

SQL Server 2017 is now supported in Windows, Linux and Docker platform

In previous posts, we saw

How to upgrade SQL Server 2017 on Ubuntu Linux to RTM Version

Simple Guide to provision SQL Server 2017 on Linux in Azure VM

In this post, we will see How to download and run SQL Server 2017 in Docker using Linux Containers

Step 1: Verify and Configure Docker Memory Settings, By default Docker is installed with 2 GB as Configured Memory usage, but SQL Server 2017 needs Min 4 GB RAM


Step 2: Open Powershell and run below command to check the current Docker images

docker ps


Currently we don’t have any images

Step 3: Run below command to download SQL Server 2017 Docker image

docker pull microsoft/mssql-server-linux:2017-latest

Depending on the internet speed, the download will take time


You can verify the downloaded images by running below command

docker images


Step 4: Run below command to start the Docker image and configure SQL Server 2017

docker run -e “ACCEPT_EULA=Y” -e “MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>” -p 1401:1433 –name sql1 -d microsoft/mssql-server-linux:2017-latest

Please change the Name, Port and Password as per your requirements, once the container is started, Please run below command to check the status of container

docker ps

We can see the container is up and running


Please launch Management Studio and connect to docker container by using the IP Address:Port, since its local machine, we will be using localhost,1401


Please run below SQL Command to verify the version of SQL Server



Please run below SQL Command to check the Server name and OS Info

FROM   sys.dm_os_host_info 


Please note that Server name will be the Container ID and not the Container name

Hope you find this post helpful !!!


Simple Guide to provision SQL Server 2017 on Linux in Azure Virtual Machine

Hi Everyone, In this article, we will see how to provision SQL Server 2017 on Linux in Azure Virtual Machine

Step 1: Please login to azure portal and go to Virtual Machine blade


Step 2: Please search for SQL Server 2017


Step 3: Please select SQL Server 2017 Developer on Ubuntu Server, I have used Ubuntu linux for this demo but you can use Red Hat or Suse Linux as well


Step 4: Please review the legal terms, select deployment model, I prefer to use Resource Manager, so that management and cleanup is easier, Please also copy the highlighted command which will be helpful for configuring the sa password for SQL Server later


Step 5: Please provide the name of the VM, select Disk type, provide user name and select Authentication Type, in this case I am using Password

Please select the Azure Subscription

For Resource group, I am creating a new one named “SQLLinux” and using Azure data center location as “East US”, please change this according to your region


Step 6: In this step, we need to select the Size of our Linux VM, I am using B2S Standard, which has 2 vCPUs and 4 GB RAM, which is good for our testing, but you can choose the size based on your requirement, after selecting the size, Please click “Select” to proceed


Step 7: In this step, we will review some of the important settings

Virtual Network – For this demo, I am creating a new Virtual Network, but if you already have other VMs running in Azure and you need this SQL Server VM to be accessible for them, Please use the existing Virtual Network

Public IP Address – I have enabled Public IP Address for this demo, but this is optional, Please don’t enable this, if you are planning to use this server only within Azure, so that it will reduce the exposure

Network Security Group (Firewall) – We will see in next step, How to configure firewall to allow external access

Auto Shutdown – This is an useful optional setting for demo or test servers, so that you can configure it to shutdown automatically based on a timing, this will reduce billing of your VM

Time Zone – Please select the time zone based on your region


Step 8: Additional Settings Please enable Monitoring for both Boot diagnostics and Guest OS diagnostics, This will help you see the Boot log for any error or messages, after making required Settings changes, Click “Ok” to proceed


Step 9:  To allow external access to SQL Server,  we need to change Network Firewall setting by adding Inbound and Outbound security rules for MSSQL Service

Note: You can do this change after creating the Virtual machine



Step 10: Review the selection options and click “Purchase” to buy and create the virtual machine


Step 11: You can review the Virtual Machine deployment progress in the screen


If you closed it, you can see from the Top right corner Notifications area


You can also see the status under Virtual Machines blade as well


Once Virtual machine is provisioned and ready, you should see the status as “Running”, see below screenshot


Step 12:  Please click on the Virtual Machine to see the settings and also to monitor the CPU/Network/Disk usage


Step 13: Configuring SQL Server in Azure Linux VM

Please connect to Azure Linux VM using any preferred SSH client, In this demo, I am using Bash Shell on Windows, since its built in Windows 10 now

Command to connect, Please type “Yes” to accept the authenticity of the host

ssh username@serveripaddress


Step 14: After logging in to VM, Please run the below command to check the status of SQL Server

sudo systemctl status mssql-server

Since we haven’t configured SA password, SQL Server is not running, so you seeing the status as “Inactive”


Step 15: Please run below command to configure SA password

sudo /opt/mssql/bin/mssql-conf setup

Please select your preferred edition of SQL Server, in this demo, we will use Developer edition, in next prompt, Please specify the SA password and press enter


Once password is setup, SQL Server 2017 will automatically run, Please run the status command again to review the SQL Server status

sudo systemctl status mssql-server


Step 16: Please run “SELECT @@VERSION” using SQLCMD utility to connect to the server to verify we are able to connect and see SQL Server version


Step 17: Now we can use SQL Server Management Studio to connect using the Public IP Address and SA password provisioned


Once connected, Please create your required databases and database objects and use as needed



SQL Server 2017 Developer Edition is up and running Azure Linux VM now in under 5 minutes

I believe you will find this post useful !!!

CONCAT_WS() – Concatenate with Separator–New String Function in SQL Server 2017

SQL Server 2017 has a new String function which supports concatenating multiple values with separator, ex. Comma (,) or Pipe (|)

This function will come handy, if you want to generate a CSV file quickly

Syntax for the function is as follows

CONCAT_WS ( separator, argument1, argument1 [, argumentN]… )

Example Usage

CREATE TABLE [dbo].[Test](
[intPK] [int] IDENTITY(1,1) NOT NULL,
[strData] [varchar](50) NOT NULL,
[intPK] ASC

INSERT INTO dbo.test (strData) VALUES (‘Test1’)
INSERT INTO dbo.test (strData) VALUES (‘Test2’)
INSERT INTO dbo.test (strData) VALUES (‘Test3’)
INSERT INTO dbo.test (strData) VALUES (‘Test4’)
INSERT INTO dbo.test (strData) VALUES (‘Test5’)

SELECT CONCAT_WS(‘|’, intPK, strData) AS Result FROM dbo.Test

In above example we are concatenating 2 fields using pipe as separator



NULL Handling

If any of the data fields has NULL, then we need to use ISNULL() or COALESCE() to handle this, else, the structure of the output will change


UPDATE dbo.Test SET strNullData=’A’ WHERE intPK=1
UPDATE dbo.Test SET strNullData=’B’ WHERE intPK=3
UPDATE dbo.Test SET strNullData=’C’ WHERE intPK=5

SELECT CONCAT_WS(‘|’, intPK, strNullData, strData) Result FROM dbo.Test

In the below output, rows 1,3 and 5 has 3 fields and rows 2 and 4 has only 2 fields


Query with ISNULL() Handling

SELECT CONCAT_WS(‘|’, intPK, ISNULL(strNullData, ”), strData) Result FROM dbo.Test

Now the below output will have consistent list of fields


Hope you find this helpful !!!

%d bloggers like this: