33 [string []]$Components ,
44 [bool ]$ForceEncryption ,
55 [string ]$SaPassword ,
6- [ValidateSet (" 2017" )]
6+ [ValidateSet (" 2017" , " 2019 " )]
77 [string ]$Version
88)
99
@@ -68,7 +68,7 @@ if ("sqlengine" -in $Components) {
6868 # Depends: python (>= 2.7.0) but it is not installable
6969 # Depends: libldap-2.4-2 but it is not installable
7070 # E: Unable to correct problems, you have held broken packages.
71- if ($IsUbuntu2404 ) {
71+ if ($IsUbuntu2404 -And $Version -Eq " 2017 " ) {
7272 Write-Error " MSSQL 2017 is not available on Ubuntu 24.04."
7373 Write-Error " See more information at https://github.com/microsoft/mssql-docker/issues/868"
7474 exit 1
@@ -80,10 +80,14 @@ if ("sqlengine" -in $Components) {
8080 # SOURCE: https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-docker-container-security?view=sql-server-ver16#encrypt-connections-to-sql-server-linux-containers
8181 & mkdir - p / opt/ mssql
8282 & openssl req - x509 - nodes - newkey rsa:2048 - subj ' /CN=sql1.contoso.com' - keyout / opt/ mssql/ mssql.key - out / opt/ mssql/ mssql.pem - days 365
83+
84+ # Microsoft recommends to mount the SQL certificates at /etc/ssl/certs and /etc/ssl/private
85+ # However, with SQL Server 2019, this always results in a file permission error
86+ # Also mounting it into the /var/opt/mssql directory works just fine
8387 $MssqlConf = @'
8488[network]
85- tlscert = /etc/ssl/certs /mssql.pem
86- tlskey = /etc/ssl/private /mssql.key
89+ tlscert = /var/opt/mssql /mssql.pem
90+ tlskey = /var/opt/mssql /mssql.key
8791tlsprotocols = 1.2
8892forceencryption = 1
8993'@
@@ -94,7 +98,7 @@ forceencryption = 1
9498 Copy-Item - Path / opt/ mssql/ mssql.pem - Destination / usr/ share/ ca- certificates/ mssql.crt
9599 & sudo dpkg- reconfigure ca- certificates
96100
97- $AdditionalContainerConfiguration = " -v /opt/mssql/mssql.conf:/var/opt/mssql/mssql.conf -v /opt/mssql/mssql.pem:/etc/ssl/certs /mssql.pem -v /opt/mssql/mssql.key:/etc/ssl/private /mssql.key"
101+ $AdditionalContainerConfiguration = " -v /opt/mssql/mssql.conf:/var/opt/mssql/mssql.conf -v /opt/mssql/mssql.pem:/var/opt/mssql /mssql.pem -v /opt/mssql/mssql.key:/var/opt/mssql /mssql.key"
98102 }
99103
100104 Write-Output " Starting a Docker Container"
@@ -106,14 +110,25 @@ forceencryption = 1
106110 Write-Output " Downloading and installing SQL Server"
107111 New-Item - ItemType Directory - Path " C:\Downloads"
108112
109- Invoke-WebRequest " https://download.microsoft.com/download/E/F/2/EF23C21D-7860-4F05-88CE-39AA114B014B/SQLEXPR_x64_ENU.exe" - OutFile " C:\Downloads\mssql.exe"
113+ switch ($Version ) {
114+ " 2017" {
115+ $DownloadUrl = " https://download.microsoft.com/download/E/F/2/EF23C21D-7860-4F05-88CE-39AA114B014B/SQLEXPR_x64_ENU.exe"
116+ $MajorVersion = 14
117+ }
118+ " 2019" {
119+ $DownloadUrl = " https://download.microsoft.com/download/7/c/1/7c14e92e-bdcb-4f89-b7cf-93543e7112d1/SQLEXPR_x64_ENU.exe"
120+ $MajorVersion = 15
121+ }
122+ }
123+
124+ Invoke-WebRequest $DownloadUrl - OutFile " C:\Downloads\mssql.exe"
110125 Start-Process - Wait - FilePath " C:\Downloads\mssql.exe" - ArgumentList / qs, / x:" C:\Downloads\setup"
111126 C:\Downloads\setup\setup.exe / q / ACTION= Install / INSTANCENAME= SQLEXPRESS / FEATURES= SQLEngine / UPDATEENABLED= 0 / SQLSVCACCOUNT= ' NT AUTHORITY\System' / SQLSYSADMINACCOUNTS= ' BUILTIN\ADMINISTRATORS' / TCPENABLED= 1 / NPENABLED= 0 / IACCEPTSQLSERVERLICENSETERMS
112127
113128 Write-Host " Configuring SQL Express ..."
114129 stop-service MSSQL`$ SQLEXPRESS
115130
116- $InstancePath = " HKLM:\software\microsoft\microsoft sql server\mssql14 .SQLEXPRESS\mssqlserver"
131+ $InstancePath = " HKLM:\software\microsoft\microsoft sql server\mssql $MajorVersion .SQLEXPRESS\mssqlserver"
117132 $SuperSocketNetLibPath = " $InstancePath \supersocketnetlib"
118133 set-itemproperty - path " $SuperSocketNetLibPath \tcp\ipall" - name tcpdynamicports - value ' '
119134 set-itemproperty - path " $SuperSocketNetLibPath \tcp\ipall" - name tcpport - value 1433
0 commit comments