add docker healthcheck for Micorsoft SQL Server on Linux

This commit is contained in:
grillazz 2017-03-10 13:46:35 +01:00
parent 303307e15d
commit b976152d31
2 changed files with 56 additions and 0 deletions

32
sqlserver/Dockerfile Normal file
View File

@ -0,0 +1,32 @@
FROM microsoft/mssql-server-linux
LABEL maintainer "the@grillazz.com"
RUN apt-get update && apt-get install -y \
curl \
apt-transport-https
#
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux/installing-the-microsoft-odbc-driver-for-sql-server-on-linux
# in article above you can find proper url to install packages appropirate to your linux version
#
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install -y \
mssql-tools
RUN apt-get install -y locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen
ENV PATH="/opt/mssql-tools/bin:${PATH}"
ENV SA_PASSWORD=Alaska2017
ENV ACCEPT_EULA=Y
COPY docker-healthcheck /usr/local/bin/
RUN chmod +x /usr/local/bin/db-healthcheck
HEALTHCHECK CMD ["docker-healthcheck"]

View File

@ -0,0 +1,24 @@
#!/bin/bash
set -eo pipefail
host="$(hostname --ip-address || echo '127.0.0.1')"
user=SA
password=$SA_PASSWORD
args=(
# force sqlserver to not use the local unix socket (test "external" connectivity)
-S $host
-U $user
-P $password
-d master
-Q "set nocount on; select count(*) from sys.objects"
-h -1
)
if select="$(sqlcmd "${args[@]}")" && [ $select > 1 ]; then
exit 0
fi
exit 1