Created
January 11, 2019 08:10
-
-
Save theiwaz/134d4e796e01de535b06580a379e22be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Remove-StoppedContainers { | |
docker container rm $(docker container ls -q) | |
} | |
function List-AllContainers { | |
docker container ls -a | |
} | |
function List-RunningContainers { | |
docker container ls | |
} | |
function Execute-Bash { | |
docker container exec -it $Args[0] bash | |
} | |
function Remove-AllContainers { | |
docker container rm -f $(docker container ls -aq) | |
} | |
function Get-ContainerIPAddress { | |
param ( | |
[string] $id | |
) | |
& docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' $id | |
} | |
function Add-ContainerIpToHosts { | |
param ( | |
[string] $name | |
) | |
$ip = docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' $name | |
$newEntry = "$ip $name #added by d2h# `r`n" | |
$path = 'C:\Windows\System32\drivers\etc\hosts' | |
$newEntry + (Get-Content $path -Raw) | Set-Content $path | |
} | |
Set-Alias drm Remove-StoppedContainers | |
Set-Alias drmf Remove-AllContainers | |
Set-Alias dip Get-ContainerIPAddress | |
Set-Alias d2h Add-ContainerIpToHosts | |
Set-Alias dla List-AllContainers | |
Set-Alias dls List-RunningContainers | |
Set-Alias deb Execute-bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment