SQL Server on Linux

2016 Dec 13 at 15:48 » Tagged as :sql-server, docker, microsoft,

It's been more than 15 years since I last opened a connection to a microsoft SQL Server. Since Mircrosoft has embracced open source in general and linux in particular it seems like a good time to try it once again. Particularly since you can now run SQL server on linux thanks to docker.

I setup sql server on my linux machine using the official docker image provided by microsoft. However when ever the server was started according to the instructions the container would run for a few seconds and then shut down. If you try to connect to it during the brief period when it's alive, you get an error like this from sqlcmd:

Sqlcmd: Error: Microsoft ODBC Driver3 for SQL Server : Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server..
Sqlcmd: Error: Microsoft ODBC Driver3 for SQL Server : TCP Provider: Error code 0x68.
Sqlcmd: Error: Microsoft ODBC Driver3 for SQL Server : Client unable to establish connection.
Sqlcmd: Error: Microsoft ODBC Driver3 for SQL Server : Client unable to establish connection due to prelogin failure.

Searched around for quite a bit but no solid answer was found. Then I re read the instructions again. Apparently this innocuous looking bit is rather important:

  • A strong system administrator (SA) password: At least 8 characters including uppercase, lowercase letters, base-10 digits and/or non-alphanumeric symbols.

If you specify too short a password the server apparently doesn't start or dies off immediately. When you run a docker image as a daemon, the container also shuts down if there are no processes running inside it. Rather lame but there are you.

Update:

To make the data persist you have to pass the container a path on the local file system for read and write. The official document says pass the parameter like what's given below, but it forgets to tell you what exactly should go into the host directory flag.

-v <host directory>:/var/opt/mssql

Almost anything will do. I used -v /var/opt/mssql:/var/opt/mssql