/
DockerUtils.psm1
36 lines (31 loc) · 1.02 KB
/
DockerUtils.psm1
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
function Remove-AllUntagedDockerImages {
docker images `
| ConvertFrom-String `
| Where-Object {$_.P2 -eq "<none>"} `
| ForEach-Object { docker rmi $_.P3 }
}
function Remove-AllDockerContainers {
docker ps -aq `
| ForEach-Object { docker stop -t 1 $_ } `
| ForEach-Object { docker rm -vf $_ }
}
function Start-ContainerWithLocalPathMounted {
param (
[string]$Image,
[string]$Entrypoint="powershell",
[string]$Command=""
)
docker run -it --rm -v "$(Resolve-Path .):C:/mount" -w C:/mount --entrypoint $Entrypoint $image $Command
}
function Get-DockerRegistryContent {
[CmdletBinding()]
Param(
$Filter=".*",
#TODO: handle https & no basic auth as well..
$RegistryEndpoint
)
$allRepos = (Invoke-RestMethod -Uri "http://$RegistryEndpoint/v2/_catalog" -Method Get ).repositories
$reposMatchingFilter = $allRepos -Match $Filter
$reposMatchingFilter | ForEach-Object {(Invoke-RestMethod -Uri "http://$RegistryEndpoint/v2/$_/tags/list" -Method Get )}
}
Export-ModuleMember -Function *