SlideShare a Scribd company logo
Microsoft SQL Server with Linux and Docker
Why would I want to use
Microsoft SQL Server on Linux?
●
You don’t. Instead, use PostgreSQL (for larger
projects) or sqllite (for trivial things).
●
When does it still make sense?
– When you locally develop on Linux for customers using
Windows and MS SQL.
– When you want to educate yourself.
– When you want to irritate people on Linuxtage!
Why would I want to use Docker for
Microsoft SQL Server?
●
Less clutter after installation.
●
Simple updates of SQL server
→ Container images are maintained by Microsoft.
●
Because Docker is hip!
Install docker
●
Depends on several things:
https://docs.docker.com/install/
●
Typically community edition (CE) sufces.
●
With Ubuntu: use Ubuntu Software shop
Install MS SQL Server
●
From docker store (requires login):
https://store.docker.com/images/mssql-server-linu
x
●
From command line:
https://docs.microsoft.com/en-us/sql/linux/quickst
art-install-connect-docker?view=sql-server-linux-2
017
$ sudo docker pull microsoft/mssql-server-
linux:2017-latest
Run the server
●
sudo docker run 
-e 'ACCEPT_EULA=Y' 
-e 'MSSQL_SA_PASSWORD=x2-B3.k4' 
-p 1401:1433 
--name mssql 
-d microsoft/mssql-server-linux:2017-latest
●
See also: quick installation guide.
●
Consider changing SA password stored in
environment variable as described there.
Running commands in the container
●
Open a shell in the container:
sudo docker exec -it mssql "bash"
●
Send a single shell command to the container:
sudo docker exec -it mssql echo hello world
Execute SQL commands
●
Use command line tool sqlcmd
●
Full path: /opt/mssql-tools/bin/sqlcmd
●
Has various options
Sqlcmd online help
●
$ sudo docker exec -it mssql 
/opt/mssql-tools/bin/sqlcmd -?
●
Useful options:
-b if SQL command fails, abort and set exit code
-S host[,port]
-U username
-P password
-Q run SQL command and exit
-q run SQL command and remain in sqlcmd console
-i some.sql to run SQL commands stored in fle
Create a new database
●
sudo docker exec -it mssql 
/opt/mssql-tools/bin/sqlcmd 
-S localhost 
-U SA -P x2-B3.k4 
-b -Q "create database linuxtage"
●
Creates data base on container volume
→ will be deleted upon docker rm <image>
●
Use more command line options to create
database on local disk
Run with mounted local volume
●
sudo mkdir /home/roskakori/mssql
●
sudo docker run 
-e 'ACCEPT_EULA=Y' 
-e 'MSSQL_SA_PASSWORD=x2-B3.k4' 
-p 1401:1433 
-v /home/roskakori/mssql:/var/opt/mssql 
--name mssql 
-d microsoft/mssql-server-linux:2017-latest
Create database on local volume
●
sudo docker exec -it mssql 
/opt/mssql-tools/bin/sqlcmd 
-S localhost 
-U SA -P x2-B3.k4 
-b -Q "create database linuxtage on
(name=’ltg_data’,
filename=’/var/opt/mssql/ltg.dat’)  log on
(name=’ltg_log’,
filename=’/var/opt/mssql/ltg.log’) "
How to access from software
●
On docker, MS SQL runs on port 1433
●
Locally mapped to port 1401
●
To access from local you need drivers
– JDBC driver:
https://docs.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sq
l-server?view=sql-server-2017
– ODBC driver for Linux
https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-mic
rosoft-odbc-driver-for-sql-server?view=sql-server-2017
– Avoid jTDS, has issues with modern servers and is not really maintained any
more
●
Supported by various programming languages
– Java: JDBC driver
– Python: pyodbc
Install local ODBC for MS SQL
●
See Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS
●
Example for Ubuntu 17.10:
– curl >/tmp/microsoft.asc  https://packages.microsoft.com/keys/microsoft.asc
– sudo apt-key add </tmp/microsoft.asc
– curl >/tmp/prod.list  https://packages.microsoft.com/confg/ubuntu/17.10/prod.list
– sudo cp /tmp/prod.list /etc/apt/sources.list.d/mssql-release.list
– sudo apt-get update
– sudo ACCEPT_EULA=Y apt-get install msodbcsql17
– sudo ACCEPT_EULA=Y apt-get install mssql-tools
– echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profle
– echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
– source ~/.bashrc
Local sqlcmd to docker
●
Port 1401 must be specifed as part of the
hostname
●
Unintuitive syntax using comma
●
sqlcmd -S localhost,1401,1401 -U SA -P x2-B3.k4 
-b -Q "select 'hello world'"
Summary
●
MS SQL on Linux
– It can be done.
– It does work.
●
Use postgreSQL if possible.
●
Use MS SQL if necessary.
●
Use sqlite if appropriate.
●
Don’t use MySQL / MariaDB.

More Related Content

PDF
Optimization_of_Virtual_Machines_for_High_Performance
PDF
OpenNebulaConf2015 2.02 Backing up your VM’s with Bacula - Alberto García
PDF
Containers > VMs
PDF
Webdevops - Neos Docker
PPTX
Couch to OpenStack: Glance - July, 23, 2013
PDF
Customizing Virtual Machine Images - Javier Fontán
PDF
Kvm optimizations
PPTX
MS Cloud Day - Building web applications with Azure storage
Optimization_of_Virtual_Machines_for_High_Performance
OpenNebulaConf2015 2.02 Backing up your VM’s with Bacula - Alberto García
Containers > VMs
Webdevops - Neos Docker
Couch to OpenStack: Glance - July, 23, 2013
Customizing Virtual Machine Images - Javier Fontán
Kvm optimizations
MS Cloud Day - Building web applications with Azure storage

What's hot (20)

PDF
Introduction to Docker
PPTX
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...
PDF
MySQL NDB 8.0 clusters in your laptop with dbdeployer
PDF
2008 MySQL Conference Recap
PDF
Happy Browser, Happy User! WordSesh 2019
PDF
Setting up mongo replica set
PDF
Dbdeployer, the universal installer
PPTX
Windows Azure Drive
PDF
PDF
Test complex database systems in your laptop with dbdeployer
PPTX
Azure Recovery Services
PDF
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
PDF
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
PPT
On MongoDB backup
PPT
High Availabiltity & Replica Sets with mongoDB
PDF
Common Pitfalls for your Drupal Site, and How to Avoid Them
PPTX
Couch to OpenStack: Nova - July, 30, 2013
PDF
Test like a_boss
PDF
Ansible
PPT
Speeding Up The Snail
Introduction to Docker
Magento Meetup Wrocław 6. "Docker for Mac - possible solutions to performance...
MySQL NDB 8.0 clusters in your laptop with dbdeployer
2008 MySQL Conference Recap
Happy Browser, Happy User! WordSesh 2019
Setting up mongo replica set
Dbdeployer, the universal installer
Windows Azure Drive
Test complex database systems in your laptop with dbdeployer
Azure Recovery Services
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
Putting rails and couch db on the cloud - Indicthreads cloud computing confe...
On MongoDB backup
High Availabiltity & Replica Sets with mongoDB
Common Pitfalls for your Drupal Site, and How to Avoid Them
Couch to OpenStack: Nova - July, 30, 2013
Test like a_boss
Ansible
Speeding Up The Snail
Ad

Similar to Microsoft SQL Server with Linux and Docker (20)

PPTX
DataDrivenMtl 20170906 - SQL Server 2017 on Linux
PPTX
Brk2051 sql server on linux and docker
PPTX
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
PPTX
Experience sql server on l inux and docker
PDF
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
PPTX
SQL on linux
PPTX
Bootcamp 2017 - SQL Server on Linux
PPTX
Sql on linux - ITpro
PPTX
Tech-Spark: SQL Server on Linux
PPTX
SQL Server: Now It's Everywhere You Want to Be
PPTX
SQL Server vNext on Linux
PPTX
SQL Server 2017 on Linux Introduction
PPTX
SQL Sever on Docker: Database Containers 3 Ways
PPTX
SQL Server 2017 on Linux Introduction
PDF
AltNet fr talks #2016.11 - news
PPTX
Red Hat Summit 2017 - Intro to SQL Server on RHEL and Open Shift
PPTX
SUSE Webinar - Introduction to SQL Server on Linux
PPTX
SQL Server in DevOps Town Hall Webinar
PPTX
Nordic infrastructure Conference 2017 - SQL Server on Linux Overview
PPTX
SQL Server on Linux - march 2017
DataDrivenMtl 20170906 - SQL Server 2017 on Linux
Brk2051 sql server on linux and docker
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
Experience sql server on l inux and docker
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
SQL on linux
Bootcamp 2017 - SQL Server on Linux
Sql on linux - ITpro
Tech-Spark: SQL Server on Linux
SQL Server: Now It's Everywhere You Want to Be
SQL Server vNext on Linux
SQL Server 2017 on Linux Introduction
SQL Sever on Docker: Database Containers 3 Ways
SQL Server 2017 on Linux Introduction
AltNet fr talks #2016.11 - news
Red Hat Summit 2017 - Intro to SQL Server on RHEL and Open Shift
SUSE Webinar - Introduction to SQL Server on Linux
SQL Server in DevOps Town Hall Webinar
Nordic infrastructure Conference 2017 - SQL Server on Linux Overview
SQL Server on Linux - march 2017
Ad

More from roskakori (18)

PDF
Expanding skill sets - Broaden your perspective on design
PPTX
Django trifft Flutter
PDF
Multiple django applications on a single server with nginx
PDF
Helpful pre commit hooks for Python and Django
PDF
Startmeeting Interessengruppe NLP NLU Graz
PDF
Helpful logging with python
PDF
Helpful logging with Java
PDF
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
PDF
Analyzing natural language feedback using python
PDF
Migration to Python 3 in Finance
PDF
Introduction to pygments
PDF
Lösungsorientierte Fehlerbehandlung
PDF
XML namespaces and XPath with Python
PDF
Erste-Hilfekasten für Unicode mit Python
PDF
Introduction to trader bots with Python
PDF
Open source projects with python
PDF
Python builds mit ant
PPT
Kanban zur Abwicklung von Reporting-Anforderungen
Expanding skill sets - Broaden your perspective on design
Django trifft Flutter
Multiple django applications on a single server with nginx
Helpful pre commit hooks for Python and Django
Startmeeting Interessengruppe NLP NLU Graz
Helpful logging with python
Helpful logging with Java
Einführung in Kommunikation und Konfliktmanagement für Software-Entwickler
Analyzing natural language feedback using python
Migration to Python 3 in Finance
Introduction to pygments
Lösungsorientierte Fehlerbehandlung
XML namespaces and XPath with Python
Erste-Hilfekasten für Unicode mit Python
Introduction to trader bots with Python
Open source projects with python
Python builds mit ant
Kanban zur Abwicklung von Reporting-Anforderungen

Recently uploaded (20)

PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Advanced IT Governance
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Modernizing your data center with Dell and AMD
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
KodekX | Application Modernization Development
Sensors and Actuators in IoT Systems using pdf
Advanced IT Governance
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Advanced Soft Computing BINUS July 2025.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Monthly Chronicles - July 2025
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Chapter 3 Spatial Domain Image Processing.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Advanced methodologies resolving dimensionality complications for autism neur...
Spectral efficient network and resource selection model in 5G networks
Modernizing your data center with Dell and AMD
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Empathic Computing: Creating Shared Understanding
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
KodekX | Application Modernization Development

Microsoft SQL Server with Linux and Docker

  • 2. Why would I want to use Microsoft SQL Server on Linux? ● You don’t. Instead, use PostgreSQL (for larger projects) or sqllite (for trivial things). ● When does it still make sense? – When you locally develop on Linux for customers using Windows and MS SQL. – When you want to educate yourself. – When you want to irritate people on Linuxtage!
  • 3. Why would I want to use Docker for Microsoft SQL Server? ● Less clutter after installation. ● Simple updates of SQL server → Container images are maintained by Microsoft. ● Because Docker is hip!
  • 4. Install docker ● Depends on several things: https://docs.docker.com/install/ ● Typically community edition (CE) sufces. ● With Ubuntu: use Ubuntu Software shop
  • 5. Install MS SQL Server ● From docker store (requires login): https://store.docker.com/images/mssql-server-linu x ● From command line: https://docs.microsoft.com/en-us/sql/linux/quickst art-install-connect-docker?view=sql-server-linux-2 017 $ sudo docker pull microsoft/mssql-server- linux:2017-latest
  • 6. Run the server ● sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=x2-B3.k4' -p 1401:1433 --name mssql -d microsoft/mssql-server-linux:2017-latest ● See also: quick installation guide. ● Consider changing SA password stored in environment variable as described there.
  • 7. Running commands in the container ● Open a shell in the container: sudo docker exec -it mssql "bash" ● Send a single shell command to the container: sudo docker exec -it mssql echo hello world
  • 8. Execute SQL commands ● Use command line tool sqlcmd ● Full path: /opt/mssql-tools/bin/sqlcmd ● Has various options
  • 9. Sqlcmd online help ● $ sudo docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -? ● Useful options: -b if SQL command fails, abort and set exit code -S host[,port] -U username -P password -Q run SQL command and exit -q run SQL command and remain in sqlcmd console -i some.sql to run SQL commands stored in fle
  • 10. Create a new database ● sudo docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P x2-B3.k4 -b -Q "create database linuxtage" ● Creates data base on container volume → will be deleted upon docker rm <image> ● Use more command line options to create database on local disk
  • 11. Run with mounted local volume ● sudo mkdir /home/roskakori/mssql ● sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=x2-B3.k4' -p 1401:1433 -v /home/roskakori/mssql:/var/opt/mssql --name mssql -d microsoft/mssql-server-linux:2017-latest
  • 12. Create database on local volume ● sudo docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P x2-B3.k4 -b -Q "create database linuxtage on (name=’ltg_data’, filename=’/var/opt/mssql/ltg.dat’) log on (name=’ltg_log’, filename=’/var/opt/mssql/ltg.log’) "
  • 13. How to access from software ● On docker, MS SQL runs on port 1433 ● Locally mapped to port 1401 ● To access from local you need drivers – JDBC driver: https://docs.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sq l-server?view=sql-server-2017 – ODBC driver for Linux https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-mic rosoft-odbc-driver-for-sql-server?view=sql-server-2017 – Avoid jTDS, has issues with modern servers and is not really maintained any more ● Supported by various programming languages – Java: JDBC driver – Python: pyodbc
  • 14. Install local ODBC for MS SQL ● See Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS ● Example for Ubuntu 17.10: – curl >/tmp/microsoft.asc https://packages.microsoft.com/keys/microsoft.asc – sudo apt-key add </tmp/microsoft.asc – curl >/tmp/prod.list https://packages.microsoft.com/confg/ubuntu/17.10/prod.list – sudo cp /tmp/prod.list /etc/apt/sources.list.d/mssql-release.list – sudo apt-get update – sudo ACCEPT_EULA=Y apt-get install msodbcsql17 – sudo ACCEPT_EULA=Y apt-get install mssql-tools – echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profle – echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc – source ~/.bashrc
  • 15. Local sqlcmd to docker ● Port 1401 must be specifed as part of the hostname ● Unintuitive syntax using comma ● sqlcmd -S localhost,1401,1401 -U SA -P x2-B3.k4 -b -Q "select 'hello world'"
  • 16. Summary ● MS SQL on Linux – It can be done. – It does work. ● Use postgreSQL if possible. ● Use MS SQL if necessary. ● Use sqlite if appropriate. ● Don’t use MySQL / MariaDB.