Skip to content

Instantly share code, notes, and snippets.

@aadennis
Last active August 4, 2020 11:09
Show Gist options
  • Save aadennis/f267e327d9843a8d4b1fdd1b0ce125cf to your computer and use it in GitHub Desktop.
Save aadennis/f267e327d9843a8d4b1fdd1b0ce125cf to your computer and use it in GitHub Desktop.
########################################## Dockerfile
#escape=`
ARG WINVER=ltsc2019
FROM mcr.microsoft.com/windows/servercore:$WINVER
WORKDIR c:\artifacts
RUN net user /add dennis
RUN net localgroup Administrators dennis /add
# USER dennis
SHELL ["powershell", "-Command"]
COPY artifacts\sql2017setup /artifacts/sql2017setup
COPY artifacts\ConfigurationFile2017Dev.ini /artifacts/ConfigurationFile2017Dev.ini
#RUN set-location sql2017setup
#RUN Start-Process c:\artifacts\sql2017setup\setup.exe -ArgumentList "CONFIGURATIONFILE=.\sql2017setup\Configuration\ConfigurationFile2017Dev.ini" -Wait
#RUN Start-Process ./setup.exe -ArgumentList "CONFIGURATIONFILE=ConfigurationFile2017Dev.ini" -Wait
RUN sql2017setup\setup.exe /CONFIGURATIONFILE=ConfigurationFile2017Dev.ini
# Remove-Item -Recurse -Force sql2017setup
RUN Stop-Service MSSQLSERVER ;
# https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-or-disable-a-server-network-protocol?view=sql-server-2017
# RUN [reflection.assembly]::LoadWithPartialName('Microsoft.SqlServer.SqlWmiManagement') ; `
# $wmi = new-object ('Microsoft.SqlServer.Management.Smo.' + 'Wmi.ManagedComputer'). ; `
# $uri = "ManagedComputer[@Name='" + (get-item env:\computername).Value + "']/ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']" ; `
# $Tcp = $wmi.GetSmoObject($uri); $Tcp.IsEnabled = $true ; $Tcp.Alter()
# HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll
#full fat
RUN Set-ItemProperty -path 'HKLM:/software\microsoft\microsoft sql server/MSSQL14.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll' -name 'tcpdynamicports' -value ''
RUN Set-ItemProperty -path 'HKLM:/software\microsoft\microsoft sql server/MSSQL14.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll' -name 'tcpport' -value '1433'
RUN Set-ItemProperty -path 'HKLM:/software\microsoft\microsoft sql server/MSSQL14.MSSQLSERVER\MSSQLServer\' -name 'LoginMode' -value '2'
#RUN Set-ItemProperty -path 'HKLM:/software\microsoft\microsoft sql server/mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name 'tcpdynamicports' -value ''
#RUN Set-ItemProperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name 'tcpport' -value '1433'
#RUN Set-ItemProperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\' -name 'LoginMode' -value '2'
COPY start.ps1 /
CMD powershell /start.ps1 -Verbose
################################### Start.ps1
Write-Verbose "Starting SQL Server"
# all seems to happens relative to c:\artifacts
#gci -r sql2017setup\Configuration
start-service MSSQLSERVER
#Start-Sleep 20
#Get-Service MSSQLSERVER
Write-Verbose Env:\COMPUTERNAME
$sa_password = "something"
Write-Verbose 'Changing SA login credentials'
$sqlcmd = "ALTER LOGIN sa with password='$sa_password'; ALTER LOGIN sa ENABLE;"
Invoke-SqlCmd -Query $sqlcmd -ServerInstance "localhost"
Write-Verbose "Started SQL Server."
$lastCheck = (Get-Date).AddSeconds(-2)
while ($true) {
Get-EventLog -LogName Application -Source "MSSQL*" -After $lastCheck | Select-Object TimeGenerated, EntryType, Message
$lastCheck = Get-Date
Start-Sleep -Seconds 2
}
############################################# build.ps1
. C:\Sandbox\DockerSandbox\utilities\DockerUtilities.ps1
$context = "C:\Sandbox\DockerSandbox\tutorial03 - Sql 2017 Dev"
$image='dennis/sql-tutorial:01-ltsc2019'
$sqlSetup = "$context\artifacts\sql2017setup"
docker image build --pull -t $image -f "context\Dockerfile" $context
######################### run.ps1
$image='dennis/sql-tutorial:01-ltsc2019'
#docker container run -t $image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment