Get Docker Containers running in a particular network
The following script can be used to start list the running containers inside a particular network along with their ips.
#! /usr/bin/zshecho "Image\tHostname\tIP";for N in $(docker ps -q) ; do echo "$(docker inspect -f '{{.Config.Image}}\t{{ .Config.Hostname }}\t' ${N}) $(docker inspect -f '{{range $i, $value := .NetworkSettings.Networks}}{{if eq $i "custom_network_name"}}{{.IPAddress}}{{end}}{{end}}' ${N})"; doneUsage example:
./network-hostsBonus tip:
Pipe the output into column -t like so to get a pretty formatted tabular output.
./network-hosts | column -tThis work is licensed under CC BY-NC-SA 4.0. Copying is an act of love — please copy!