Update June 3, 2017: The team has revised the docker image and the bash file is gone, presumably with its logic broken up in to various locations. Still I’m glad I grabbed this when I did to satisfy my curiosity!
Microsoft has created 4 official Docker images for SQL Server: SQL Server for Linux, SQL Server Developer Edition, SQL Server Express and (windows) SQL Server vNext) . They can be found on the Docker hub (e.g. https://hub.docker.com/r/microsoft/mssql-server-linux/) and there is also a Github repository for them at github.com/Microsoft/mssql-docker. Some of the files that go along with that image are not on Github. The Dockerfile files for each image run some type of startup script. The Windows images have a PowerShell script called start.ps1. You can see those in the Github repo. The Linux image runs a bash file called sqlservr.sh. That’s not included in the repo though and I was curious what it did.
Note: I wrote a blog post about using the SQL Server for Linux container (Mashup: SQL Server on Linux in Docker on a Mac with Visual Studio Code) and I’m also writing an article about using the containers for my July MSDN Magazine Data Points column (watch this space).
Still a bit of a bash noob, I learned how to read a file from a docker container on ..you guessed it…StackOverflow. Following those instructions, I created a snapshot of my running container
➜ MySqlServerLinuImage git:(master) docker commit juliesqllinux mysnapshot sha256:9b552a1e24df7652af0c6c265ae5e2d7cb7832586c431d4b480c30663ab713f0
and ran the snapshot with bash:
➜ MySqlServerLinuImage git:(master) docker run -t -i mysnapshot bin/bash root@2a6f950face2:/#
Then at the new prompt (#), used ls to get the listing
root@2a6f950face2:/# ls SqlCmdScript.sql SqlCmdStartup.sh bin boot dev entrypoint.sh etc home install.sh lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
then navigated to folder where the bash file is and listed its contents:
root@2a6f950face2:/opt/mssql/bin# ls compress-dump.sh generate-core.sh mssql-conf paldumper sqlpackage sqlservr sqlservr.sh
Once I was there I used the cat command to list out the contents of the sqlservr.sh file and see what it does. Here is the secret sauce in case, like me, you NEED to know what’s going on under the covers!
root@2a6f950face2:/opt/mssql/bin# cat sqlservr.sh #!/bin/bash # # Microsoft(R) SQL Server(R) launch script for Docker # ACCEPT_EULA=${ACCEPT_EULA:-} SA_PASSWORD=${SA_PASSWORD:-} #COLLATION=${COLLATION:-SQL_Latin1_General_CP1_CI_AS} have_sa_password="" #have_collation="" sqlservr_setup_prefix="" configure="" reconfigure="" # Check system memory # let system_memory="$(awk '/MemTotal/ {print $2}' /proc/meminfo) / 1024" if [ $system_memory -lt 3250 ]; then echo "ERROR: This machine must have at least 3.25 gigabytes of memory to install Microsoft(R) SQL Server(R)." exit 1 fi # Create system directories # mkdir -p /var/opt/mssql/data mkdir -p /var/opt/mssql/etc mkdir -p /var/opt/mssql/log # Check the EULA # if [ "$ACCEPT_EULA" != "Y" ] && [ "$ACCEPT_EULA" != "y" ]; then echo "ERROR: You must accept the End User License Agreement before this container" > /dev/stderr echo "can start. The End User License Agreement can be found at " > /dev/stderr echo "http://go.microsoft.com/fwlink/?LinkId=746388." > /dev/stderr echo "" echo "Set the environment variable ACCEPT_EULA to 'Y' if you accept the agreement." > /dev/stderr exit 1 fi # Configure SQL engine # if [ ! -f /var/opt/mssql/data/master.mdf ]; then configure=1 if [ ! -z "$SA_PASSWORD" ] || [ -f /var/opt/mssql/etc/sa_password ]; then have_sa_password=1 fi # if [ ! -z "$COLLATION" ] || [ -f /var/opt/mssql/etc/collation ]; then # have_collation=1 # fi if [ -z "$have_sa_password" ]; then echo "ERROR: The system administrator password is not configured. You can set the" > /dev/stderr echo "password via environment variable (SA_PASSWORD) or configuration file" > /dev/stderr echo "(/var/opt/mssql/etc/sa_password)." > /dev/stderr exit 1 fi fi # If user wants to reconfigure, set reconfigure flag # if [ -f /var/opt/mssql/etc/reconfigure ]; then reconfigure=1 fi # If we need to configure or reconfigure, run through configuration # logic # if [ "$configure" == "1" ] || [ "$reconfigure" == "1" ]; then sqlservr_setup_options="" # if [ -f /var/opt/mssql/etc/collation ]; then # sqlservr_setup_options+="-q $(cat /var/opt/mssql/etc/collation)" # else # if [ ! -z "$COLLATION" ]; then # sqlservr_setup_options+="-q $COLLATION " # fi # fi set +e cd /var/opt/mssql echo 'Configuring Microsoft(R) SQL Server(R)...' if [ -f /var/opt/mssql/etc/sa_password ]; then SQLSERVR_SA_PASSWORD_FILE=/var/opt/mssql/etc/sa_password /opt/mssql/bin/sqlservr --setup $sqlservr_setup_options 2>&1 > /var/opt/mssql/log/setup-$(date +%Y%m%d-%H%M%S).log elif [ ! -z "$SA_PASSWORD" ]; then SQLSERVR_SA_PASSWORD_FILE=<(echo -n "$SA_PASSWORD") /opt/mssql/bin/sqlservr --setup $sqlservr_setup_options 2>&1 > /var/opt/mssql/log/setup-$(date +%Y%m%d-%H%M%S).log else if [ ! -z '$sqlservr_setup_options' ]; then /opt/mssql/bin/sqlservr --setup $sqlservr_setup_options 2>&1 > /var/opt/mssql/log/setup-$(date +%Y%m%d-%H%M%S).log fi fi retcode=$? if [ $retcode != 0 ]; then echo "Microsoft(R) SQL Server(R) setup failed with error code $retcode. Please check the setup log in /var/opt/mssql/log for more information." > /dev/stderr exit 1 fi set -e rm -f /var/opt/mssql/etc/reconfigure rm -f /var/opt/mssql/etc/sa_password echo "Configuration complete." fi # Start SQL Server # exec /opt/mssql/bin/sqlservr $*