Skip to content

Instantly share code, notes, and snippets.

@ipedrazas
Created September 18, 2014 22:13
Show Gist options
  • Star 80 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save ipedrazas/2c93f6e74737d1f8a791 to your computer and use it in GitHub Desktop.
Save ipedrazas/2c93f6e74737d1f8a791 to your computer and use it in GitHub Desktop.
List Docker Container Names and IPs
function drips(){
docker ps -q | xargs -n 1 docker inspect --format '{{ .NetworkSettings.IPAddress }} {{ .Name }}' | sed 's/ \// /'
}
@brccabral
Copy link

If anyone interested, GammaGames repo has many updates now, https://github.com/GammaGames/dz . Specially for speed, running the inspect in a single command returns data much faster

# Networks
        network_inspect=$(docker network inspect --format "{{slice .Id 0 12}}""\
,{{.Name}}""\
,{{range .IPAM.Config}}{{.Subnet}}{{end}}""\
,{{range .IPAM.Config}}{{if (index . \"Gateway\")}}{{.Gateway}}{{end}}{{end}}" \
            "${1}")
# Containers
        container_inspect=$(docker container inspect --format "{{slice .Id 0 12}}""\
,{{slice .Name 1}}""\
,{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}""\
,{{range \$p, \$conf := .NetworkSettings.Ports}}{{if \$conf}}{{if ne (index \$conf 0).HostIp \"0.0.0.0\"}}{{(index \$conf 0).HostIp}}:{{end}}{{(index \$conf 0).HostPort}}{{else}}null{{end}}:{{\$p}} {{end}}""\
,{{range \$k, \$v := .NetworkSettings.Networks}}{{\$k}}{{end}}""\
,{{range .NetworkSettings.Networks}}{{.Gateway}} {{end}}" \
            ${1})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment