Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Forked from sixeyed/profile.ps1
Last active March 14, 2019 04:00
Show Gist options
  • Save alecthegeek/e36aba83ff42ae8af7e247462fca5ae6 to your computer and use it in GitHub Desktop.
Save alecthegeek/e36aba83ff42ae8af7e247462fca5ae6 to your computer and use it in GitHub Desktop.
PowerShell profile with aliases for common Docker commands
function Remove-StoppedContainers {
docker container rm $(docker container ls -q)
}
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
Function docc {&"c:\Program Files\Docker\Docker\Resources\bin\docker.exe" container $Args}
Function doci {&"c:\Program Files\Docker\Docker\Resources\bin\docker.exe" image $Args}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment