File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed
samples/manage/windows-containers/mssql-server-2014-express-windows Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ MAINTAINER Perry Skountrianos
12
12
# set environment variables
13
13
ENV sql_express_download_url "https://download.microsoft.com/download/1/5/6/156992E6-F7C7-4E55-833D-249BD2348138/ENU/x64/SQLEXPR_x64_ENU.exe"
14
14
ENV sa_password _
15
+ ENV attach_dbs "[]"
15
16
16
17
# make install files accessible
17
18
COPY . /
@@ -22,9 +23,9 @@ RUN powershell -Command (New-Object System.Net.WebClient).DownloadFile('%sql_exp
22
23
23
24
RUN powershell -Command \
24
25
set-strictmode -version latest ; \
25
- stop-service MSSQL`$%sqlinstance% ; \
26
+ stop-service MSSQL`$SQLEXPRESS ; \
26
27
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
27
28
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
28
29
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2 ;
29
30
30
- CMD powershell ./start %sa_password%
31
+ CMD powershell ./start -sa_password %sa_password% -attach_dbs \"%attach_dbs%\"
Original file line number Diff line number Diff line change 1
- # The script sets the sa password and start the SQl Service
1
+ # The script sets the sa password and start the SQL Service
2
+ # Also it attaches additional database from the disk
3
+ # The format for attach_dbs
2
4
3
5
param (
4
6
[Parameter (Mandatory = $false )]
5
- [string ]$sa_password
7
+ [string ]$sa_password ,
8
+
9
+ [Parameter (Mandatory = $false )]
10
+ [string ]$attach_dbs
6
11
)
7
12
8
13
# start the service
14
+ Write-Verbose " Starting SQL Server"
9
15
start-service MSSQL`$ SQLEXPRESS
10
16
11
-
12
17
if ($sa_password -ne " _" ){
18
+ Write-Verbose " Changing SA login credentials"
13
19
$sqlcmd = " ALTER LOGIN sa with password=" + " '" + $sa_password + " '" + " ;ALTER LOGIN sa ENABLE;"
14
20
Invoke-Sqlcmd - Query $sqlcmd - ServerInstance " .\SQLEXPRESS"
15
21
}
16
22
23
+ $attach_dbs = $attach_dbs | ConvertFrom-Json
24
+
25
+ if ($null -ne $attach_dbs ){
26
+ Write-Verbose " Attaching database(s)"
27
+ Foreach ($db in $attach_dbs )
28
+ {
29
+ $files = @ ();
30
+ Foreach ($file in $db.dbFiles )
31
+ {
32
+ $files += " (FILENAME = 'N$ ( $file ) ')" ;
33
+ }
34
+
35
+ $files = $files -join " ,"
36
+ $sqlcmd = " sp_detach_db $ ( $db.dbName ) ;GO;CREATE DATABASE $ ( $db.dbName ) ON $ ( $files ) FOR ATTACH ;GO;"
37
+
38
+ Write-Host Invoke-Sqlcmd - Query $ ($sqlcmd ) - ServerInstance " .\SQLEXPRESS"
39
+ Invoke-Sqlcmd - Query $sqlcmd - ServerInstance " .\SQLEXPRESS"
40
+ }
41
+ }
42
+
17
43
while ($true ) { Start-Sleep - Seconds 3600 }
You can’t perform that action at this time.
0 commit comments