Skip to content

Instantly share code, notes, and snippets.

@SQLDBAWithABeard
Last active May 27, 2022 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SQLDBAWithABeard/3f27d6ca22a12a469cf4e5ef1f5ce955 to your computer and use it in GitHub Desktop.
Save SQLDBAWithABeard/3f27d6ca22a12a469cf4e5ef1f5ce955 to your computer and use it in GitHub Desktop.
SQL 2022 Contained
Houston, we have a problem.
You will need to add the link to the 2022 container when it is available to the docker compose file
version: '3.7'
services:
beardsql01:
image: /mssql/server:latest
container_name: beardsql01
hostname: beardsql01
ports:
- "15588:1433"
- "5022:5022"
networks:
- BeardsMagicNetwork
environment:
- ACCEPT_EULA=Y
- MSSQL_ENABLE_HADR=1
- MSSQL_AGENT_ENABLED=true
- MSSQL_SA_PASSWORD=dbatools.IO
beardsql02:
image: /mssql/server:latest
container_name: beardsql02
hostname: beardsql02
ports:
- "15589:1433"
- "5023:5023"
networks:
- BeardsMagicNetwork
environment:
- ACCEPT_EULA=Y
- MSSQL_ENABLE_HADR=1
- MSSQL_AGENT_ENABLED=true
- MSSQL_SA_PASSWORD=dbatools.IO
networks:
BeardsMagicNetwork:
docker compose -f PATH TO\docker-compose.yml up -d
# I use the dbatools docker cert from https://github.com/dataplat/docker
docker cp "G:\OneDrive\Documents\GitHub\ClonedForked\dbatools etc\docker\sqlinstance\sql\AGCertificate2021_2121.cer" beardsql01:/tmp/AGCertificate2021_2121.cer
docker cp "G:\OneDrive\Documents\GitHub\ClonedForked\dbatools etc\docker\sqlinstance\sql\AGCertificate2021_2121.pvk" beardsql01:/tmp/AGCertificate2021_2121.pvk
docker cp "G:\OneDrive\Documents\GitHub\ClonedForked\dbatools etc\docker\sqlinstance\sql\AGCertificate2021_2121.cer" beardsql02:/tmp/AGCertificate2021_2121.cer
docker cp "G:\OneDrive\Documents\GitHub\ClonedForked\dbatools etc\docker\sqlinstance\sql\AGCertificate2021_2121.pvk" beardsql02:/tmp/AGCertificate2021_2121.pvk
$query = "CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'dbatools.IO'
GO
CREATE CERTIFICATE AGCertificate2021_2121 FROM FILE ='/tmp/AGCertificate2021_2121.cer' WITH PRIVATE KEY(FILE='/tmp/AGCertificate2021_2121.pvk', DECRYPTION BY PASSWORD='dbatools.IO')
GO
CREATE ENDPOINT [hadr_endpoint]
STATE=STARTED
AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = CERTIFICATE [AGCertificate2021_2121]
, ENCRYPTION = REQUIRED ALGORITHM AES)
GO"
$query1 = "CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'dbatools.IO'
GO
CREATE CERTIFICATE AGCertificate2021_2121 FROM FILE ='/tmp/AGCertificate2021_2121.cer' WITH PRIVATE KEY(FILE='/tmp/AGCertificate2021_2121.pvk', DECRYPTION BY PASSWORD='dbatools.IO')
GO
CREATE ENDPOINT [hadr_endpoint]
STATE=STARTED
AS TCP (LISTENER_PORT = 5023, LISTENER_IP = ALL)
FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = CERTIFICATE [AGCertificate2021_2121]
, ENCRYPTION = REQUIRED ALGORITHM AES)
GO"
$securePassword = ('dbatools.IO' | ConvertTo-SecureString -asPlainText -Force)
$continercredential = New-Object System.Management.Automation.PSCredential('sa', $securePassword)
$2022 = Connect-DbaInstance -SqlInstance 'localhost,15588' -SqlCredential $continercredential
$20221 = Connect-DbaInstance -SqlInstance 'localhost,15589' -SqlCredential $continercredential
Invoke-DbaQuery -SqlInstance $2022 -Query $query
Invoke-DbaQuery -SqlInstance $20221 -Query $query1
New-DbaDatabase -SqlInstance $2022 -Name jeremy_db
Backup-DbaDatabase -SqlInstance $2022 -Database jeremy_db
## then use SSMS 2019 to create a contained availability group
$2022 = Connect-DbaInstance -SqlInstance 'localhost,15588' -SqlCredential $continercredential
# expolore it
$2022.AvailabilityGroups[0]
$2022.AvailabilityGroups[0].AvailabilityDatabases
$2022.AvailabilityGroups[0].Script()
docker compose -f PATHTO\docker-compose.yml down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment