Life's random bits By b1thunt3r (aka Ishan Jain)…
Running SQL Server for Linux in Docker

Running SQL Server for Linux in Docker

Ishan jain
For the latest project I worked on, I decided to test SQL Server 2017 for Linux.

Disclaimer: Currently I am employed by Microsoft, but my views and thoughts are still my own. The reason I joined Microsoft was, the work Microsoft have been doing for last couple of years in Open Source Space. Today I am a advocate for Open Source representing Microsoft.

I have always had problem with having SQL Server (even Express) installed on my main or dev machine. Usually I have a full blown Windows VM for SQL Server. So when it came time to design the database for I was contemplating whether I should install a new VM and then install SQL Server on it. And yes, I did think about it, I needed to have the database offline, so Azure SQL was out of question.

Then a little birdie reminded me of SQL Server for Linux, and I could run it in a container in my Docker Desktop for Windows. The possibilities are infinite. I can run an isolated instance of SQL Server, without sacrificing the CPU and RAM for either the SQL or the host. So both SQL and the Visual Studio will be able to play nicely with each other.

docker run -d --name sql2017 -m 2G -v C:\Docker\sqldata\:/var/opt/mssql/data -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Str0ngPassw0rd!%$' -e 'MSSQL_PID=Express' -p 1433:1433 mcr.microsoft.com/mssql/server:2017-latest-ubuntu
  • SQL Server needs a minimum of 2GB of RAM, this can be set with -m 2G.
  • I mounted a folder instead of a volume, so that I will have access to the SQL data even if there was a catastrophic failure with the container.
  • The container also require some environmental variables (for more info check the Docker Hub page for MSSQL Server):
    • -e 'ACCEPT_EULA=Y
    • -e 'SA_PASSWORD=Str0ngPassw0rd!%$'
    • -e 'MSSQL_PID=Express'
  • I also forwarded the SQL port, so that I could use SQL Server Management Studio with it.
  • I need to have ubuntu in tag for docker image, otherwise docker will run a Windows container instead.

That is how easy it is today to get SQL Server installed, no more ISO to download and install. If you want you can always install SQL Server in Linux with either apt or yum.

It is also good to have MSSQL Tools container pulled from the Hub, just in case.