From 33586685d53ff6d464a216e0682ae60106186fd6 Mon Sep 17 00:00:00 2001 From: Perry Skountrianos Date: Fri, 10 Jun 2016 16:24:15 -0700 Subject: [PATCH] Updated DockerFile: User specified sa password --- .../dockerfile | 16 ++++++++-------- .../mssql-server-2014-express-windows/readme.md | 9 ++++----- .../mssql-server-2014-express-windows/start.ps1 | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 samples/manage/windows-containers/mssql-server-2014-express-windows/start.ps1 diff --git a/samples/manage/windows-containers/mssql-server-2014-express-windows/dockerfile b/samples/manage/windows-containers/mssql-server-2014-express-windows/dockerfile index df3f4849..8bd3e52b 100644 --- a/samples/manage/windows-containers/mssql-server-2014-express-windows/dockerfile +++ b/samples/manage/windows-containers/mssql-server-2014-express-windows/dockerfile @@ -10,21 +10,21 @@ FROM microsoft/dotnet35 MAINTAINER Perry Skountrianos # set environment variables -ENV SQL_EXPRESS_DOWNLOAD_URL "https://download.microsoft.com/download/1/5/6/156992E6-F7C7-4E55-833D-249BD2348138/ENU/x64/SQLEXPR_x64_ENU.exe" -ENV SQL_SERVER_SA_PASSWORD "Password1" +ENV sql_express_download_url "https://download.microsoft.com/download/1/5/6/156992E6-F7C7-4E55-833D-249BD2348138/ENU/x64/SQLEXPR_x64_ENU.exe" +ENV sa_password _ -# set working directory +# make install files accessible +COPY . / WORKDIR / # download and install Microsoft SQL 2014 Express Edition in one step -RUN powershell -Command (New-Object System.Net.WebClient).DownloadFile('%SQL_EXPRESS_DOWNLOAD_URL%', 'sqlexpress.exe') && /sqlexpress.exe /qs /x:setup && /setup/setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SECURITYMODE=SQL /SAPWD=%SQL_SERVER_SA_PASSWORD% /SQLSVCACCOUNT="NT AUTHORITY\System" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS && del /F /Q sqlexpress.exe && rd /q /s setup +RUN powershell -Command (New-Object System.Net.WebClient).DownloadFile('%sql_express_download_url%', 'sqlexpress.exe') && /sqlexpress.exe /qs /x:setup && /setup/setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT="NT AUTHORITY\System" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS && del /F /Q sqlexpress.exe && rd /q /s setup RUN powershell -Command \ set-strictmode -version latest ; \ - stop-service MSSQL`$SQLEXPRESS ; \ + stop-service MSSQL`$%sqlinstance% ; \ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \ - start-service MSSQL`$SQLEXPRESS + set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2 ; -CMD powershell -Command while ($true) { Start-Sleep -Seconds 3600 } -EXPOSE 1433 \ No newline at end of file +CMD powershell ./start %sa_password% \ No newline at end of file diff --git a/samples/manage/windows-containers/mssql-server-2014-express-windows/readme.md b/samples/manage/windows-containers/mssql-server-2014-express-windows/readme.md index d03e3533..6e706da6 100644 --- a/samples/manage/windows-containers/mssql-server-2014-express-windows/readme.md +++ b/samples/manage/windows-containers/mssql-server-2014-express-windows/readme.md @@ -1,5 +1,5 @@ -# mssql-server-2014-express-windows -The goal of this Dockerfile is to help developers get started using SQL Server 2014 Express in Windows Containers. The Dockerfile downloads and installs SQL Server 2014 Express with the default setup parameters that could be changed (if needed) after the image is installed. +# mssql-server-2014-express-windows +This Dockerfile helps developers to get started using SQL Server 2014 Express in Windows Containers. The Dockerfile downloads and installs SQL Server 2014 Express with the default setup parameters that could be changed (if needed) after the image is installed. Note: This dockerfile is based on Buc Rogers' work that can be found [here] (https://github.com/brogersyh/Dockerfiles-for-windows/tree/master/sqlexpress) @@ -35,8 +35,8 @@ To run this sample, you need the following prerequisites. ## Run this sample Use the Dockerfile and execute the following two commands to build and run sqlexpress: -1. docker build -t sqlexpress . -2. docker run -it -p 1433:1433 sqlexpress cmd +1. docker build --env sa_password= . +2. docker run -it -p 1433:1433 cmd @@ -44,7 +44,6 @@ Use the Dockerfile and execute the following two commands to build and run sqlex **High Level Description** The Dockerfile downloads and installs SQL Server 2014 Express with the following default setup parameters that could be changed (if needed) after the image is installed. -- sa password: Password1 - Collation: SQL_Latin1_General_CP1_CI_AS - SQL Instance Name: SQLEXPRESS - Root Directory: C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL diff --git a/samples/manage/windows-containers/mssql-server-2014-express-windows/start.ps1 b/samples/manage/windows-containers/mssql-server-2014-express-windows/start.ps1 new file mode 100644 index 00000000..1fa234ab --- /dev/null +++ b/samples/manage/windows-containers/mssql-server-2014-express-windows/start.ps1 @@ -0,0 +1,17 @@ +# The script sets the sa password and start the SQl Service + +param( +[Parameter(Mandatory=$false)] +[string]$sa_password +) + +# start the service +start-service MSSQL`$SQLEXPRESS + + +if($sa_password -ne "_"){ + $sqlcmd = "ALTER LOGIN sa with password=" +"'" + $sa_password + "'" + ";ALTER LOGIN sa ENABLE;" + Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS" +} + +while ($true) { Start-Sleep -Seconds 3600 } \ No newline at end of file