-
Notifications
You must be signed in to change notification settings - Fork 50
/
docker_sql_express.ps1
21 lines (19 loc) · 1.04 KB
/
docker_sql_express.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
param(
[Parameter(Mandatory=$true)]
[string]$dockerImage
)
IF ($(docker ps -aq -f label=deployer=akkadotnet).Length -gt 0) {
docker stop $(docker ps -aq -f label=deployer=akkadotnet)
docker rm $(docker ps -aq -f label=deployer=akkadotnet)
}
$env:container_name = $null
$env:container_ip = $null
Write-Host "Starting SQL Server Express Docker container..."
$env:container_name = "akka-$(New-Guid)"
$container_id = docker run -d --name $env:container_name -l deployer=akkadotnet -p 1433:1433 -e ACCEPT_EULA=Y $dockerImage
Start-Sleep -Seconds 30
docker exec $container_id sqlcmd -q "CREATE LOGIN akkadotnet with password='akkadotnet', CHECK_POLICY=OFF; ALTER SERVER ROLE dbcreator ADD MEMBER akkadotnet;"
$env:container_ip = docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container_id
[Environment]::SetEnvironmentVariable("container_name", $env:container_name, "User")
[Environment]::SetEnvironmentVariable("container_ip", $env:container_ip, "User")
Write-Host "SQL container started at IP addr: $($env:container_ip)"