SQL Server Docker container with Microsoft SQL Server for Linux images

 

Preamble

First time I have read it it sounded like a bad joke but SQL Server is available for download on Linux and Docker. While I initially planned to test it on Linux I have finally decided to test under Docker for the low modification it will trigger on my test virtual machine. So SQL Server Docker container here we go !

It is pending since long time but Microsoft has finally made it real: Announcing SQL Server on Linux public preview, first preview of next release of SQL Server.

Testing has been done using a virtual machine (under Virtualbox) running Oracle Linux 7.2 and latest release of Docker i.e. 1.12.3. The kernel Docker requirement is quite high as you need Kernel 3.10 minimum or Unbreakable Enterprise Kernel Release 4 (4.1.12) minimum. It means for example that RHEL 6 is out of scope…

As I’m behind a proxy to avoid any certificate error I start by importing my proxy certificate inside my virtual machine as we have seen in my other Docker post.

The version that has been made available is (select @@version):

Microsoft SQL Server vNext (CTP1) - 14.0.1.246 (X64) Nov  1 2016 23:24:39 Copyright (c) Microsoft Corporation on Linux (Ubuntu 15.10)

Docker installation

There is an official Install Docker on Oracle Linux page on Docker web site. As explained first create the /etc/yum.repos.d/docker.repo repository file containing:

[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/oraclelinux/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

Docker installation is then as simple as:

[root@server4 ~]# yum install docker-engine

Before starting it I configure my proxy server in Docker configuration file:

[root@server4 ~]# cat /etc/systemd/system/docker.service.d/docker.conf
[Service]
Environment="HTTP_PROXY=http://account:password@proxyserver.domain.com:proxy_port/"

Finally start Docker engine with (you light also want to make the service auto start):

[root@server4 ~]# systemctl start docker
[root@server4 ~]# systemctl is-enabled docker.service
disabled
[root@server4 ~]# docker version
Client:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:
 OS/Arch:      linux/amd64
 
Server:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:
 OS/Arch:      linux/amd64

SQL Server Docker container creation

Pull the official SQL Server image with:

[root@server4 ~]# docker pull microsoft/mssql-server-linux
Using default tag: latest
latest: Pulling from microsoft/mssql-server-linux
7dcf5a444392: Pull complete
759aa75f3cee: Pull complete
3fa871dc8a2b: Pull complete
224c42ae46e7: Pull complete
76c0e9bd5603: Pull complete
f6f1f8309800: Pull complete
2f187a07b883: Pull complete
Digest: sha256:238006156e6bcc098105759fc0e16130cc053673cdec6b567f17b4c7e79ed75a
Status: Downloaded newer image for microsoft/mssql-server-linux:latest
[root@server4 ~]# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
microsoft/mssql-server-linux   latest              dddada24e950        6 days ago          952.2 MB

Then I created my SQL Server Docker container with (that failed immediately but first restart worked):

[root@server4 ~]# docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=secure_password' -p 1433:1433 -d microsoft/mssql-server-linux
24c618d406cf7e254c9e394b8cbf4d54c7edb0668825cd342118492d52d80e29
[root@server4 ~]# docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
24c618d406cf        microsoft/mssql-server-linux   "/bin/sh -c /opt/mssq"   3 seconds ago       Up 2 seconds        0.0.0.0:1433->1433/tcp   elegant_aryabhata
[root@server4 ~]# docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS                              PORTS               NAMES
24c618d406cf        microsoft/mssql-server-linux   "/bin/sh -c /opt/mssq"   6 seconds ago       Exited (1) Less than a second ago                       elegant_aryabhata
[root@server4 ~]# docker start 24c618d406cf
24c618d406cf
[root@server4 ~]# docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
24c618d406cf        microsoft/mssql-server-linux   "/bin/sh -c /opt/mssq"   40 seconds ago      Up 25 seconds       0.0.0.0:1433->1433/tcp   elegant_aryabhata

The port was correctly initialized for listening but I was not able to connect with sa / secure_password:

[root@server4 ~]# netstat -an | grep 1433
tcp6       0      0 :::1433                 :::*                    LISTEN

To investigate you might connect to your SQL Server Docker container with bash:

[root@server4 ~]# docker exec -ti 24c618d406cf /bin/bash
root@24c618d406cf:/# tail /var/opt/mssql/log/errorlog
2016-11-21 14:21:52.20 spid7s      The tempdb database has 1 data file(s).
2016-11-21 14:21:52.21 spid20s     The Service Broker endpoint is in disabled or stopped state.
2016-11-21 14:21:52.21 spid20s     The Database Mirroring endpoint is in disabled or stopped state.
2016-11-21 14:21:52.23 spid20s     Service Broker manager has started.
2016-11-21 14:21:52.30 spid5s      Recovery is complete. This is an informational message only. No user action is required.
2016-11-21 14:23:20.65 Logon       Error: 18456, Severity: 14, State: 7.
2016-11-21 14:23:20.65 Logon       Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 192.168.56.1]
2016-11-21 14:23:30.61 Logon       Error: 18456, Severity: 14, State: 7.
2016-11-21 14:23:30.61 Logon       Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 192.168.56.1]

Or display SQL Server Docker container log directly with:

[root@server4 ~]# docker exec -ti 24c618d406cf tail /var/opt/mssql/log/errorlog
2016-11-21 14:21:52.20 spid7s      The tempdb database has 1 data file(s).
2016-11-21 14:21:52.21 spid20s     The Service Broker endpoint is in disabled or stopped state.
2016-11-21 14:21:52.21 spid20s     The Database Mirroring endpoint is in disabled or stopped state.
2016-11-21 14:21:52.23 spid20s     Service Broker manager has started.
2016-11-21 14:21:52.30 spid5s      Recovery is complete. This is an informational message only. No user action is required.
2016-11-21 14:23:20.65 Logon       Error: 18456, Severity: 14, State: 7.
2016-11-21 14:23:20.65 Logon       Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 192.168.56.1]
2016-11-21 14:23:30.61 Logon       Error: 18456, Severity: 14, State: 7.
2016-11-21 14:23:30.61 Logon       Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 192.168.56.1]

I have (difficulty) understood that the password I have chosen was not following Microsoft security rules, so destroyed and recreated my SQL Server Docker container with:

[root@server4 ~]# docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
24c618d406cf        microsoft/mssql-server-linux   "/bin/sh -c /opt/mssq"   5 minutes ago       Up 5 minutes        0.0.0.0:1433->1433/tcp   elegant_aryabhata
[root@server4 ~]# docker stop 24c618d406cf
24c618d406cf
[root@server4 ~]# docker rm 24c618d406cf
24c618d406cf

And recreated it with a different sa password:

[root@server4 ~]# docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password001*' -p 1433:1433 -d microsoft/mssql-server-linux
9acc1e09d39ba9066e39636b30b7d018ba77c236b6b6812fdcfe8d9906131627
[root@server4 ~]# docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
9acc1e09d39b        microsoft/mssql-server-linux   "/bin/sh -c /opt/mssq"   4 seconds ago       Up 3 seconds        0.0.0.0:1433->1433/tcp   big_archimedes

I successfully used SQL Developer to connect to it from my desktop directly:

sql_server_docker01
sql_server_docker01

References

This entry was posted in SQL Server and tagged . Bookmark the permalink.

4 thoughts on “SQL Server Docker container with Microsoft SQL Server for Linux images

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>