Created
September 18, 2014 22:13
-
-
Save ipedrazas/2c93f6e74737d1f8a791 to your computer and use it in GitHub Desktop.
List Docker Container Names and IPs
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 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})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For now, I am happy with this.
Other changes: