Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create a SQL-on-Linux container, and restore the AdventureWorks2016 DB
$BakURL = ""
$BakFile = "$($Home)\Downloads\AdventureWorks2016.bak"
Invoke-WebRequest -Uri $BakURL -OutFile $BakFile
mkdir C:\SQLData\Docker\SQLDev02
#dir C:\SQLData\Docker\SQLDev02 | OGV -PassThru | Remove-Item
Copy-Item -Path "$($Home)\Downloads\AdventureWorks2016.bak" -Destination C:\SQLData\Docker\SQLDev02
<# Create a Container with a volume mounted from the host #>
docker run -d -p 10002:1433 -v C:\SQLData\Docker\SQLDev02:/sqlserver --env ACCEPT_EULA=Y --env SA_PASSWORD=Test1234 --name testcontainer02 microsoft/mssql-server-linux:latest
<# Make sure to say Yes and add your username & password so Docker can connect to the volume-location. #>
<# via Invoke-SqlCmd to Host-Mount #>
New-StoredCredential -Target "SqlDocker" -UserName "sa" -Password "Test1234" -Persist LocalMachine
$cred = Get-StoredCredential -Target "SqlDocker"
Invoke-Sqlcmd -ServerInstance 'localhost,10002' -Credential $cred -Query "SELECT name from sys.databases"
#Requires -Modules SqlServer
Invoke-Sqlcmd -ServerInstance 'localhost,10002' -Credential $cred -Query "
RESTORE DATABASE [AdventureWorks2016] FROM DISK = N'/sqlserver/AdventureWorks2016.bak' WITH FILE = 1,
MOVE N'AdventureWorks2016_Data' TO N'/sqlserver/AdventureWorks2016_Data.mdf',
MOVE N'AdventureWorks2016_Log' TO N'/sqlserver/AdventureWorks2016_Log.ldf',
Invoke-Sqlcmd -ServerInstance 'localhost,10002' -Credential $cred -Query "SELECT name from sys.databases"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.