Skip to content

Commit f26d193

Browse files
author
knom
committed
Fixed bugs
1 parent 301a5aa commit f26d193

File tree

2 files changed

+122
-114
lines changed

2 files changed

+122
-114
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,111 @@
1-
# mssql-server-2014-express-windows
2-
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.
3-
4-
Note: This dockerfile is based on Buc Rogers' work that can be found [here] (https://github.com/brogersyh/Dockerfiles-for-windows/tree/master/sqlexpress)
5-
6-
### Contents
7-
8-
[About this sample](#about-this-sample)<br/>
9-
[Before you begin](#before-you-begin)<br/>
10-
[Run this sample](#run-this-sample)<br/>
11-
[Sample details](#sample-details)<br/>
12-
[Disclaimers](#disclaimers)<br/>
13-
[Related links](#related-links)<br/>
14-
15-
<a name=about-this-sample></a>
16-
17-
## About this sample
18-
19-
1. **Applies to:** SQL Server 2014 Express, Windows Server Technical Preview 4 or later
20-
5. **Authors:** Perry Skountrianos [perrysk-msft], Max Knor [knom]
21-
22-
<a name=before-you-begin></a>
23-
24-
## Before you begin
25-
26-
To run this sample, you need the following prerequisites.
27-
28-
**Software prerequisites:**
29-
30-
You can run the container with the following command.
31-
(Note the you'll need Windows Server Core TP5 v10.0.14300.1000.)
32-
33-
````
34-
docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password=<YOUR SA PASSWORD> --env attach_dbs="<DB-JSON-CONFIG>" microsoft/mssql-server-2014-express-windows
35-
````
36-
37-
- **-p HostPort:containerPort** is for port-mapping a container network port to a host port.
38-
- **-v HostPath:containerPath** is for mounting a folder from the host inside the container.
39-
40-
This can be used for saving database outside of the container.
41-
42-
<a name=run-this-sample></a>
43-
44-
## Run this sample
45-
46-
The image provides two environment variables to optionally set: </br>
47-
- **sa_password**: Sets the sa password and enables the sa login
48-
- **attach_dbs**: The configuration for attaching custom DBs (.mdf, .ldf files).
49-
50-
This should be a JSON string, in the following format (note the use of SINGLE quotes!)
51-
```
52-
[
53-
{
54-
'dbName': 'MaxDb',
55-
'dbFiles': ['C:\\temp\\maxtest.mdf',
56-
'C:\\temp\\maxtest_log.ldf']
57-
},
58-
{
59-
'dbName': 'PerryDb',
60-
'dbFiles': ['C:\\temp\\perrytest.mdf',
61-
'C:\\temp\\perrytest_log.ldf']
62-
}
63-
]
64-
```
65-
66-
This is an array of databases, which can have zero to N databases.
67-
68-
Each consisting of:
69-
- **dbName**: The name of the database
70-
- **dbFiles**: An array of one or many absolute paths to the .MDF and .LDF files.
71-
72-
**Note:**
73-
The path has double backslashes for escaping!
74-
The path refers to files **within the container**. So make sure to include them in the image or mount them via **-v**!
75-
76-
77-
This example shows all parameters in action:
78-
```
79-
docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env attach_dbs="[{'dbName':'MaxTest','dbFiles':['C:\\temp\\maxtest.mdf','C:\\temp\\maxtest_log.
80-
ldf']}]" microsoft/mssql-server-2014-express-windows
81-
```
82-
83-
<a name=sample-details></a>
84-
85-
## Sample details
86-
87-
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.
88-
- Collation: SQL_Latin1_General_CP1_CI_AS
89-
- SQL Instance Name: SQLEXPRESS
90-
- Root Directory: C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL
91-
- Language: English (United Stated)
92-
93-
<a name=disclaimers></a>
94-
95-
## Disclaimers
96-
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.
97-
98-
<a name=related-links></a>
99-
100-
## Related Links
101-
<!-- Links to more articles. Remember to delete "en-us" from the link path. -->
102-
103-
For more information, see these articles:
104-
- [Windows Containers] (https://msdn.microsoft.com/en-us/virtualization/windowscontainers/about/about_overview)
105-
- [Windows-based containers: Modern app development with enterprise-grade control] (https://www.youtube.com/watch?v=Ryx3o0rD5lY&feature=youtu.be)
106-
- [Windows Containers: What, Why and How] (https://channel9.msdn.com/Events/Build/2015/2-704)
107-
- [SQL Server in Windows Containers] (https://blogs.msdn.microsoft.com/sqlserverstorageengine/2016/03/21/sql-server-in-windows-containers/#comments)
1+
# mssql-server-2014-express-windows
2+
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.
3+
4+
Note: This dockerfile is based on Buc Rogers' work that can be found [here] (https://github.com/brogersyh/Dockerfiles-for-windows/tree/master/sqlexpress)
5+
6+
### Contents
7+
8+
[About this sample](#about-this-sample)<br/>
9+
[Before you begin](#before-you-begin)<br/>
10+
[Run this sample](#run-this-sample)<br/>
11+
[Sample details](#sample-details)<br/>
12+
[Disclaimers](#disclaimers)<br/>
13+
[Related links](#related-links)<br/>
14+
15+
<a name=about-this-sample></a>
16+
17+
## About this sample
18+
19+
1. **Applies to:** SQL Server 2014 Express, Windows Server Technical Preview 4 or later
20+
5. **Authors:** Perry Skountrianos [perrysk-msft], Max Knor [knom]
21+
22+
<a name=before-you-begin></a>
23+
24+
## Before you begin
25+
26+
To run this sample, you need the following prerequisites.
27+
28+
**Software prerequisites:**
29+
30+
You can run the container with the following command.
31+
(Note the you'll need Windows Server Core TP5 v10.0.14300.1000.)
32+
33+
````
34+
docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password=<YOUR SA PASSWORD> --env attach_dbs="<DB-JSON-CONFIG>" microsoft/mssql-server-2014-express-windows
35+
````
36+
37+
- **-p HostPort:containerPort** is for port-mapping a container network port to a host port.
38+
- **-v HostPath:containerPath** is for mounting a folder from the host inside the container.
39+
40+
This can be used for saving database outside of the container.
41+
42+
- **-it** can be used to show the verbose output of the SQL startup script.
43+
44+
Use this to debug the container in case of issues.
45+
46+
<a name=run-this-sample></a>
47+
48+
## Run this sample
49+
50+
The image provides two environment variables to optionally set: </br>
51+
- **sa_password**: Sets the sa password and enables the sa login
52+
- **attach_dbs**: The configuration for attaching custom DBs (.mdf, .ldf files).
53+
54+
This should be a JSON string, in the following format (note the use of SINGLE quotes!)
55+
```
56+
[
57+
{
58+
'dbName': 'MaxDb',
59+
'dbFiles': ['C:\\temp\\maxtest.mdf',
60+
'C:\\temp\\maxtest_log.ldf']
61+
},
62+
{
63+
'dbName': 'PerryDb',
64+
'dbFiles': ['C:\\temp\\perrytest.mdf',
65+
'C:\\temp\\perrytest_log.ldf']
66+
}
67+
]
68+
```
69+
70+
This is an array of databases, which can have zero to N databases.
71+
72+
Each consisting of:
73+
- **dbName**: The name of the database
74+
- **dbFiles**: An array of one or many absolute paths to the .MDF and .LDF files.
75+
76+
**Note:**
77+
The path has double backslashes for escaping!
78+
The path refers to files **within the container**. So make sure to include them in the image or mount them via **-v**!
79+
80+
81+
This example shows all parameters in action:
82+
```
83+
docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env attach_dbs="[{'dbName':'MaxTest','dbFiles':['C:\\temp\\maxtest.mdf','C:\\temp\\maxtest_log.
84+
ldf']}]" microsoft/mssql-server-2014-express-windows
85+
```
86+
87+
<a name=sample-details></a>
88+
89+
## Sample details
90+
91+
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.
92+
- Collation: SQL_Latin1_General_CP1_CI_AS
93+
- SQL Instance Name: SQLEXPRESS
94+
- Root Directory: C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL
95+
- Language: English (United Stated)
96+
97+
<a name=disclaimers></a>
98+
99+
## Disclaimers
100+
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.
101+
102+
<a name=related-links></a>
103+
104+
## Related Links
105+
<!-- Links to more articles. Remember to delete "en-us" from the link path. -->
106+
107+
For more information, see these articles:
108+
- [Windows Containers] (https://msdn.microsoft.com/en-us/virtualization/windowscontainers/about/about_overview)
109+
- [Windows-based containers: Modern app development with enterprise-grade control] (https://www.youtube.com/watch?v=Ryx3o0rD5lY&feature=youtu.be)
110+
- [Windows Containers: What, Why and How] (https://channel9.msdn.com/Events/Build/2015/2-704)
111+
- [SQL Server in Windows Containers] (https://blogs.msdn.microsoft.com/sqlserverstorageengine/2016/03/21/sql-server-in-windows-containers/#comments)

samples/manage/windows-containers/mssql-server-2014-express-windows/start.ps1

+11-7
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@ if($sa_password -ne "_"){
2020
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
2121
}
2222

23-
$attach_dbs = $attach_dbs | ConvertFrom-Json
23+
$attach_dbs_cleaned = $attach_dbs.TrimStart('\\').TrimEnd('\\')
2424

25-
if ($null -ne $attach_dbs){
26-
Write-Verbose "Attaching database(s)"
27-
Foreach($db in $attach_dbs)
25+
Write-Verbose "Attach Database configuration passed: $($attach_dbs_cleaned)"
26+
27+
$dbs = $attach_dbs_cleaned | ConvertFrom-Json
28+
29+
if ($null -ne $dbs -And $dbs.Length -gt 0){
30+
Write-Verbose "Attaching $($dbs.Length) database(s)"
31+
Foreach($db in $dbs)
2832
{
2933
$files = @();
3034
Foreach($file in $db.dbFiles)
3135
{
32-
$files += "(FILENAME = 'N$($file)')";
36+
$files += "(FILENAME = N'$($file)')";
3337
}
3438

3539
$files = $files -join ","
36-
$sqlcmd = "sp_detach_db $($db.dbName);GO;CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;GO;"
40+
$sqlcmd = "sp_detach_db $($db.dbName);CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;"
3741

38-
Write-Host Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance ".\SQLEXPRESS"
42+
Write-Verbose "Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance '.\SQLEXPRESS'"
3943
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
4044
}
4145
}

0 commit comments

Comments
 (0)