From 301a5aa14ad6d66895b7ab4df6aa3820c99ad230 Mon Sep 17 00:00:00 2001 From: knom Date: Wed, 22 Jun 2016 10:37:13 +0200 Subject: [PATCH 1/2] Updated --- .../readme.md | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) 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 6b194926..67a5afb2 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 @@ -31,7 +31,7 @@ You can run the container with the following command. (Note the you'll need Windows Server Core TP5 v10.0.14300.1000.) ```` -docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password= --env attach_dbs="" -v microsoft/mssql-server-2014-express-windows +docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password= --env attach_dbs="" microsoft/mssql-server-2014-express-windows ```` - **-p HostPort:containerPort** is for port-mapping a container network port to a host port. @@ -44,20 +44,35 @@ docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password= -- sa_password: Sets the sa password and enables the sa login -- attach_dbs: The configuration for attaching custom DBs (.mdf, .ldf files). +- **sa_password**: Sets the sa password and enables the sa login +- **attach_dbs**: The configuration for attaching custom DBs (.mdf, .ldf files). - This should be a JSON string, formed like the following (note the SINGLE quotes and everything in one line): + This should be a JSON string, in the following format (note the use of SINGLE quotes!) ``` -[{'dbName':'MaxDb','dbFiles':['C:\\temp\\maxtest.mdf','C:\\temp\\maxtest_log. -ldf']},{'dbName':'PerryDb','dbFiles':['C:\\temp\\perrytest.mdf','C:\\temp\\perrytest_log. -ldf']}] + [ + { + 'dbName': 'MaxDb', + 'dbFiles': ['C:\\temp\\maxtest.mdf', + 'C:\\temp\\maxtest_log.ldf'] + }, + { + 'dbName': 'PerryDb', + 'dbFiles': ['C:\\temp\\perrytest.mdf', + 'C:\\temp\\perrytest_log.ldf'] + } + ] ``` - There can be zero to many databases in the array. - - dbName: The name of the database - - dbFiles: An array of absolute paths to the .MDF and .LDF files. - Can be one or many, note that the path has double backslashes for escaping! + This is an array of databases, which can have zero to N databases. + + Each consisting of: + - **dbName**: The name of the database + - **dbFiles**: An array of one or many absolute paths to the .MDF and .LDF files. + + **Note:** + The path has double backslashes for escaping! + The path refers to files **within the container**. So make sure to include them in the image or mount them via **-v**! + This example shows all parameters in action: ``` From f26d1934eba458b84632ef6795b6b159bef5f53f Mon Sep 17 00:00:00 2001 From: knom Date: Wed, 22 Jun 2016 11:00:43 +0200 Subject: [PATCH 2/2] Fixed bugs --- .../readme.md | 218 +++++++++--------- .../start.ps1 | 18 +- 2 files changed, 122 insertions(+), 114 deletions(-) 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 67a5afb2..f0ce1d69 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,107 +1,111 @@ -# mssql-server-2014-express-windows -This Dockerfile helps developers to get started using SQL Server 2014 Express in Windows Server Core Containers. The file downloads and installs SQL Server 2014 Express with the default setup parameters. - -Note: This dockerfile is based on Buc Rogers' work that can be found [here] (https://github.com/brogersyh/Dockerfiles-for-windows/tree/master/sqlexpress) - -### Contents - -[About this sample](#about-this-sample)
-[Before you begin](#before-you-begin)
-[Run this sample](#run-this-sample)
-[Sample details](#sample-details)
-[Disclaimers](#disclaimers)
-[Related links](#related-links)
- - - -## About this sample - -1. **Applies to:** SQL Server 2014 Express, Windows Server Technical Preview 4 or later -5. **Authors:** Perry Skountrianos [perrysk-msft], Max Knor [knom] - - - -## Before you begin - -To run this sample, you need the following prerequisites. - -**Software prerequisites:** - -You can run the container with the following command. -(Note the you'll need Windows Server Core TP5 v10.0.14300.1000.) - -```` -docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password= --env attach_dbs="" microsoft/mssql-server-2014-express-windows -```` - -- **-p HostPort:containerPort** is for port-mapping a container network port to a host port. -- **-v HostPath:containerPath** is for mounting a folder from the host inside the container. - - This can be used for saving database outside of the container. - - - -## Run this sample - -The image provides two environment variables to optionally set:
-- **sa_password**: Sets the sa password and enables the sa login -- **attach_dbs**: The configuration for attaching custom DBs (.mdf, .ldf files). - - This should be a JSON string, in the following format (note the use of SINGLE quotes!) - ``` - [ - { - 'dbName': 'MaxDb', - 'dbFiles': ['C:\\temp\\maxtest.mdf', - 'C:\\temp\\maxtest_log.ldf'] - }, - { - 'dbName': 'PerryDb', - 'dbFiles': ['C:\\temp\\perrytest.mdf', - 'C:\\temp\\perrytest_log.ldf'] - } - ] - ``` - - This is an array of databases, which can have zero to N databases. - - Each consisting of: - - **dbName**: The name of the database - - **dbFiles**: An array of one or many absolute paths to the .MDF and .LDF files. - - **Note:** - The path has double backslashes for escaping! - The path refers to files **within the container**. So make sure to include them in the image or mount them via **-v**! - - -This example shows all parameters in action: -``` -docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env attach_dbs="[{'dbName':'MaxTest','dbFiles':['C:\\temp\\maxtest.mdf','C:\\temp\\maxtest_log. -ldf']}]" microsoft/mssql-server-2014-express-windows -``` - - - -## Sample details - -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. -- Collation: SQL_Latin1_General_CP1_CI_AS -- SQL Instance Name: SQLEXPRESS -- Root Directory: C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL -- Language: English (United Stated) - - - -## Disclaimers -The code included in this sample is not intended to be a set of best practices on how to build scalable enterprise grade applications. This is beyond the scope of this quick start sample. - - - -## Related Links - - -For more information, see these articles: -- [Windows Containers] (https://msdn.microsoft.com/en-us/virtualization/windowscontainers/about/about_overview) -- [Windows-based containers: Modern app development with enterprise-grade control] (https://www.youtube.com/watch?v=Ryx3o0rD5lY&feature=youtu.be) -- [Windows Containers: What, Why and How] (https://channel9.msdn.com/Events/Build/2015/2-704) -- [SQL Server in Windows Containers] (https://blogs.msdn.microsoft.com/sqlserverstorageengine/2016/03/21/sql-server-in-windows-containers/#comments) +# mssql-server-2014-express-windows +This Dockerfile helps developers to get started using SQL Server 2014 Express in Windows Server Core Containers. The file downloads and installs SQL Server 2014 Express with the default setup parameters. + +Note: This dockerfile is based on Buc Rogers' work that can be found [here] (https://github.com/brogersyh/Dockerfiles-for-windows/tree/master/sqlexpress) + +### Contents + +[About this sample](#about-this-sample)
+[Before you begin](#before-you-begin)
+[Run this sample](#run-this-sample)
+[Sample details](#sample-details)
+[Disclaimers](#disclaimers)
+[Related links](#related-links)
+ + + +## About this sample + +1. **Applies to:** SQL Server 2014 Express, Windows Server Technical Preview 4 or later +5. **Authors:** Perry Skountrianos [perrysk-msft], Max Knor [knom] + + + +## Before you begin + +To run this sample, you need the following prerequisites. + +**Software prerequisites:** + +You can run the container with the following command. +(Note the you'll need Windows Server Core TP5 v10.0.14300.1000.) + +```` +docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password= --env attach_dbs="" microsoft/mssql-server-2014-express-windows +```` + +- **-p HostPort:containerPort** is for port-mapping a container network port to a host port. +- **-v HostPath:containerPath** is for mounting a folder from the host inside the container. + + This can be used for saving database outside of the container. + +- **-it** can be used to show the verbose output of the SQL startup script. + + Use this to debug the container in case of issues. + + + +## Run this sample + +The image provides two environment variables to optionally set:
+- **sa_password**: Sets the sa password and enables the sa login +- **attach_dbs**: The configuration for attaching custom DBs (.mdf, .ldf files). + + This should be a JSON string, in the following format (note the use of SINGLE quotes!) + ``` + [ + { + 'dbName': 'MaxDb', + 'dbFiles': ['C:\\temp\\maxtest.mdf', + 'C:\\temp\\maxtest_log.ldf'] + }, + { + 'dbName': 'PerryDb', + 'dbFiles': ['C:\\temp\\perrytest.mdf', + 'C:\\temp\\perrytest_log.ldf'] + } + ] + ``` + + This is an array of databases, which can have zero to N databases. + + Each consisting of: + - **dbName**: The name of the database + - **dbFiles**: An array of one or many absolute paths to the .MDF and .LDF files. + + **Note:** + The path has double backslashes for escaping! + The path refers to files **within the container**. So make sure to include them in the image or mount them via **-v**! + + +This example shows all parameters in action: +``` +docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env attach_dbs="[{'dbName':'MaxTest','dbFiles':['C:\\temp\\maxtest.mdf','C:\\temp\\maxtest_log. +ldf']}]" microsoft/mssql-server-2014-express-windows +``` + + + +## Sample details + +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. +- Collation: SQL_Latin1_General_CP1_CI_AS +- SQL Instance Name: SQLEXPRESS +- Root Directory: C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL +- Language: English (United Stated) + + + +## Disclaimers +The code included in this sample is not intended to be a set of best practices on how to build scalable enterprise grade applications. This is beyond the scope of this quick start sample. + + + +## Related Links + + +For more information, see these articles: +- [Windows Containers] (https://msdn.microsoft.com/en-us/virtualization/windowscontainers/about/about_overview) +- [Windows-based containers: Modern app development with enterprise-grade control] (https://www.youtube.com/watch?v=Ryx3o0rD5lY&feature=youtu.be) +- [Windows Containers: What, Why and How] (https://channel9.msdn.com/Events/Build/2015/2-704) +- [SQL Server in Windows Containers] (https://blogs.msdn.microsoft.com/sqlserverstorageengine/2016/03/21/sql-server-in-windows-containers/#comments) 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 index f28672f1..a4a78b4a 100644 --- a/samples/manage/windows-containers/mssql-server-2014-express-windows/start.ps1 +++ b/samples/manage/windows-containers/mssql-server-2014-express-windows/start.ps1 @@ -20,22 +20,26 @@ if($sa_password -ne "_"){ Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS" } -$attach_dbs = $attach_dbs | ConvertFrom-Json +$attach_dbs_cleaned = $attach_dbs.TrimStart('\\').TrimEnd('\\') -if ($null -ne $attach_dbs){ - Write-Verbose "Attaching database(s)" - Foreach($db in $attach_dbs) +Write-Verbose "Attach Database configuration passed: $($attach_dbs_cleaned)" + +$dbs = $attach_dbs_cleaned | ConvertFrom-Json + +if ($null -ne $dbs -And $dbs.Length -gt 0){ + Write-Verbose "Attaching $($dbs.Length) database(s)" + Foreach($db in $dbs) { $files = @(); Foreach($file in $db.dbFiles) { - $files += "(FILENAME = 'N$($file)')"; + $files += "(FILENAME = N'$($file)')"; } $files = $files -join "," - $sqlcmd = "sp_detach_db $($db.dbName);GO;CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;GO;" + $sqlcmd = "sp_detach_db $($db.dbName);CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;" - Write-Host Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance ".\SQLEXPRESS" + Write-Verbose "Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance '.\SQLEXPRESS'" Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS" } }