forked from OneIdentity/SafeguardDevOpsService
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoke-docker-run.ps1
More file actions
48 lines (37 loc) · 1.44 KB
/
invoke-docker-run.ps1
File metadata and controls
48 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,Position=0)]
[string]$ImageType = "alpine",
[Parameter(Mandatory=$false)]
[int]$Port = 443,
[Parameter(Mandatory=$false)]
[switch]$DebugContainer
)
if (-not $PSBoundParameters.ContainsKey("ErrorAction")) { $ErrorActionPreference = "Stop" }
if (-not $PSBoundParameters.ContainsKey("Verbose")) { $VerbosePreference = $PSCmdlet.GetVariableValue("VerbosePreference") }
Import-Module -Name "$PSScriptRoot\docker\docker-include.psm1" -Scope Local -Force
$ImageType = $ImageType.ToLower()
Get-SafeguardDockerFile $ImageType # Make sure the ImageType exists
if (-not (Get-Command "docker" -EA SilentlyContinue))
{
throw "Unable to find docker command. Is docker installed on this machine?"
}
$ImageName = "oneidentity/safeguard-devops:$ImageType"
$ContainerName = "safeguard-devops-runtime"
Write-Host "Rebuilding the image: $ImageName ..."
& "$PSScriptRoot/invoke-docker-build.ps1" $ImageType
Write-Host "Clean up any old container named $ContainerName ..."
$Exists = (& docker ps -a -f name=$ContainerName -q)
if ($Exists)
{
docker rm $ContainerName
}
if ($DebugContainer)
{
& docker run --name "$ContainerName" -p "${Port}:4443" --cap-add=NET_ADMIN -it "$ImageName" "/bin/bash"
}
else
{
Write-Host "Running interactive container ($ContainerName) for $ImageName on port $Port ..."
& docker run --name "$ContainerName" -p "${Port}:4443" --cap-add=NET_ADMIN -it "$ImageName"
}