Thursday, January 19, 2017

Install MS SQL Server on Debian Jessie (through Docker)

Recently Microsoft released some previews of the Linux version of SQL Server.

At present the supported Linux distributions are only Red Hat Enterprise Linux 7.2, Ubuntu 16.04 and SUSE Linux Enterprise Server v12 SP2.

Installing it in other distributions (I'm using Debian Jessie) can be successful, but surely more difficult.

An alternative in these cases is using a Docker container.

Microsoft provides a Docker image for the server part, so running the server is as simple as typing the following command:
docker run -e 'ACCEPT_EULA=Y' \
    -e 'SA_PASSWORD=<yourstrong Passw0rd>' \
    -p 1433:1433 -v <host directory>:/var/opt/mssql \
    -d microsoft/mssql-server-linux
More difficult is the installation of SQL Server Tools, needed for connecting and querying the server. In this case Microsoft doesn't provide a Docker image, so you can only install them on the supported platforms.

Fortunately we can build a docker image by ourself.

Using the following Dockerfile:
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y curl apt-transport-https debconf-utils apt-utils
RUN curl | apt-key add -
RUN curl | tee /etc/apt/sources.list.d/msprod.list
RUN echo mssql-tools mssql-tools/accept_eula boolean Y|debconf-set-selections
RUN echo msodbcsql msodbcsql/accept_eula boolean true|debconf-set-selections
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev-utf16
RUN ln -sfn /opt/mssql-tools/bin/sqlcmd- /usr/bin/sqlcmd 
RUN ln -sfn /opt/mssql-tools/bin/bcp- /usr/bin/bcp
RUN locale-gen en_US en_US.UTF-8
RUN locale-gen it_IT it_IT.UTF-8
RUN dpkg-reconfigure locales
Build the docker image:
docker build -t mssql-tools:latest .
And run it typing:
docker run -it mssql-tools:latest /bin/bash
Now in this container you can user the MS SQL Tools for connecting to the running server:
sqlcmd -S <ms sql server container IP> -U SA -P '<yourstrong Passw0rd>'
For finding the IP of the container running the SQL Server, you can type the following command on your host:
docker inspect mssql-server|grep IPAddress


gibsonherry said...

I found this blog after a long time which is really helpful to let understand different approaches. I am going to adopt these new point to my career and thankful for this help.
Windows Server Standard

Girish Achar said...

Hi Ben,

I got this error ...

Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
unixodbc-dev-utf16 : Depends: unixodbc-utf16 (= 2.3.1-2) but it is not going to be installed
Depends: odbcinst1debian2-utf16 (= 2.3.1-2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
The command '/bin/sh -c apt-get update && ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev-utf16' returned a non-zero code: 100