MICROSOFT SQL SERVER AS A DOCKER CONTAINER

MICROSOFT SQL SERVER AS A DOCKER CONTAINER

Nobody could have ever imagined Microsoft SQL Server running on Linux. I appreciate the foresight of Satya Nadella, CEO Microsoft embracing Linux and OpenSource.

Now as Microsoft SQL Server vNext CTP 1.1 is available for Ubuntu, RHEL7 & CentOS7, how about running it as a container.

To run SQL Server vNext CTP 1.1, you need Minimum of 4 GB of RAM on your host.

Pulling Image

Use Docker pull command to pull the image from docker hub.

~# docker pull swapnillinux/mssql

Creating Container

  • run - create & start container
  • --name - name the container as mymssql
  • -p 1433:1433 - forward port 1433 from your host to 1433 of container
  • -d - Run container in background using Docker image swapnillinux/mssql
~# docker run --name=mymssql -p 1433:1433 -d swapnillinux/mssql

Check Status using docker ps command

~# docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
ec4b65b5d6ec        swapnillinux/mssql   "/opt/mssql/bin/sqlse"   22 seconds ago      Up 21 seconds       0.0.0.0:1433->1433/tcp   mymssql

Check some logs of your container using docker logs command

~# docker logs mymssql
This is an evaluation version.  There are [174] days left in the evaluation period.
2016-12-21 12:56:24.72 Server      Microsoft SQL Server vNext (CTP1.1) - 14.0.100.187 (X64) 
	Dec 10 2016 02:51:11 
	Copyright (C) 2016 Microsoft Corporation. All rights reserved.
	on Linux (CentOS Linux 7 (Core))
...
...
...
...
...
2016-12-21 12:56:27.26 spid6s      Polybase feature disabled.
2016-12-21 12:56:27.26 spid6s      Clearing tempdb database.
2016-12-21 12:56:27.85 spid6s      Starting up database 'tempdb'.
2016-12-21 12:56:28.14 spid6s      The tempdb database has 1 data file(s).
2016-12-21 12:56:28.15 spid20s     The Service Broker endpoint is in disabled or stopped state.
2016-12-21 12:56:28.16 spid20s     The Database Mirroring endpoint is in disabled or stopped state.
2016-12-21 12:56:28.18 spid20s     Service Broker manager has started.
2016-12-21 12:56:28.26 spid5s      Recovery is complete. This is an informational message only. No user action is required.

Looks like its up and running.

Now Test it

Use SQL Server tools on Linux to connect to MSSQL server.

on RHEL or CentOS

~# wget https://packages.microsoft.com/config/rhel/7/prod.repo -O /etc/yum.repos.d/msprod.repo

~# yum install mssql-tools

on Ubuntu

~# curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

~# wget https://packages.microsoft.com/config/ubuntu/16.04/prod.list -O /etc/apt/sources.list.d/msprod.list

~# apt-get update 
~# apt-get install mssql-tools

Query SQL Server

This Docker Image was created with SA password as 'RedHat123'. You can change it later on.

[root@centos ~]# sqlcmd -S localhost -U SA -P 'RedHat123'
1> SELECT Name from sys.Databases;
2> GO
Name                                                                                                                            
--------------------------------------------------------------------------------------------------------------------------------
master                                                                                                                          
tempdb                                                                                                                          
model                                                                                                                           
msdb                                                                                                                            

(4 rows affected)
1> 

Create Database

1> CREATE DATABASE test;
2> GO

Use Database test

1> USE test;
2> GO
Changed database context to 'test'.
1> 

Create Table

1> CREATE TABLE student (id INT, name NVARCHAR(50), rollno INT);
2> GO
1> 

Insert Some Data

1> INSERT INTO student VALUES (1, 'joey', 1123);
2> INSERT INTO student VALUES (2, 'phoebe', 1154);
3> GO

(1 rows affected)

(1 rows affected)
1> 

Finally get it back

1> SELECT * FROM student;
2> GO
id          name                                               rollno     
----------- -------------------------------------------------- -----------
          1 joey                                                      1123
          2 phoebe                                                    1154

(2 rows affected)
1> 

Other tools that run on Windows to connect to this SQL Server Docker container:

  • SQL Server Management Studio (SSMS)
  • Windows PowerShell
  • SQL Server Data Tools (SSDT)

Thats it for now, Enjoy :)


Like it? Click here to Tweet your feedback