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.

1
2
3
#! /usr/bin/zsh
echo "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})"; done

Usage example:

1
./network-hosts

Bonus tip:
Pipe the output into column -t like so to get a pretty formatted tabular output.

1
./network-hosts | column -t
All content is licensed under CC BY-NC-SA 4.0. Copying is an act of love - please copy!
More cool websites: Prev | Hotline Webring | Next
Built with Hugo
Theme Stack designed by Jimmy