-
-
Save ipedrazas/2c93f6e74737d1f8a791 to your computer and use it in GitHub Desktop.
function drips(){ | |
docker ps -q | xargs -n 1 docker inspect --format '{{ .NetworkSettings.IPAddress }} {{ .Name }}' | sed 's/ \// /' | |
} |
Anyone wanna add these changes to the repo version? https://github.com/GammaGames/dz
It’s also got a command to sh into containers.
showing local ports might be useful too, sometimes I bind stuff to 127.0.0.1
and they don’t show up
Edit: brccabral, thanks for the pr! I've also updated the ip function to show host ip when the container isn't listening on 0.0.0.0
since your changes made that way easier to implement, here's what that looks like with a bunch of different configs:
Container Ports
5432:5432/tcp
127.0.0.1:9090:80/tcp
127.0.0.1:8082:80/tcp
127.0.0.1:8084:80/tcp
127.0.0.1:9093:80/tcp
127.0.0.1:8083:80/tcp
host
127.0.0.1:9092:80/tcp
9200:9200/tcp 9300:9300/tcp
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})
my one liner solution works like @zeroows but adds CR when containers have multiple networks
docker container ls -q | xargs -r docker container inspect | jq -r '.[]|"\(.NetworkSettings.Networks[].IPAddress|select(length > 0) // "# no ip address:") \(.Name|sub("^/"; "")|sub("_1$"; "")|sub("-1$"; ""))"'
For now, I am happy with this.
Other changes: