Running Microsoft SQL Server on Linux in Docker

One of the organizations that recently consulted me for advice, no longer willing to be extortion by Microsoft's high licensing fees, and plans to replace all Windows Server with Linux (Ubuntu). No big deal for services written in PHP, Java, and other cross platform languages. But some of the systems use MicroSoft SQL Server as their Database. The permanent cure is to migrate to MySQL, MariaDB, or other OpenSource Databases. But it takes time to translate all schema and queries. The other solution is to use Microsoft SQL Server on Linux in Docker as a temporary workaround.

Env: Ubuntu 16.04

Run official docker image

Pull and run

$ docker run --name mssql-server-linux -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux


$ docker ps

7c73a9a4d0ef microsoft/mssql-server-linux "/bin/sh -c /opt/m..." 25 minutes ago Up 25 minutes>1433/tcp mssql-server-linux

Connect and run T-SQL

Once it's running, you can connect it with built in mssql tools

$ docker exec -it mssql-server-linux /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'yourStrong(!)Password'


Try some command

1> SELECT Name from sys.Databases;
2> GO

(4 rows affected)
2> GO
1> USE testdb;
2> GO
Changed database context to 'testdb'.
1> CREATE TABLE inventory (id INT, name NVARCHAR(50), quantity INT);
2> GO
1> INSERT INTO inventory VALUES (1, 'banana', 150);
2> INSERT INTO inventory VALUES (2, 'orange', 154);
3> GO
(1 rows affected)
(1 rows affected)
1> SELECT * FROM inventory WHERE quantity > 152;
2> GO
id          name                                               quantity   
----------- -------------------------------------------------- -----------
          2 orange                                                     154

(1 rows affected)

Additional Info

Data dir

root@7c73a9a4d0ef:~# ls /var/opt/mssql/data/

master.mdf   model.mdf     msdbdata.mdf  tempdb.mdf   testdb.mdf
mastlog.ldf  modellog.ldf  msdblog.ldf   templog.ldf  testdb_log.ldf

In Dockerfile we can see there's no MSSQL server is directly executed

CMD /opt/mssql/bin/

If you want to build your app extending from this image and has your own, this is an example



I am really happy with your blog because your article is very unique and powerful for new reader.

Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts
rpa training in chennai

Thanks for sharing, now a days many of the applications are running in docker for security reason and easily can move from one environment to another.

DevOps Training in Chennai | DevOps Training

We are providing best Big Data and Analytics Courses in Chennai in Chennai, which helps to learn advanced techniques by experienced industry processionals.This course syllabus design from beginner to advance, it is job oriented course and jobseeker can learn new demand technology very depth and easily.

Big Data and Analytics Courses in Chennai
Big Data and Analytics Courses

Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.
Best Aws training Institute in chennai

I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

Great efforts put it to find the list of articles. Thanks for your article. We are also one of the best sources to learn
Angular JS Training in Chennai | Angular JS Training Institute in Chennai

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.