Skip to content

Instantly share code, notes, and snippets.

@afriza
Last active June 10, 2022 01:21
Show Gist options
  • Save afriza/f857c2da90ab3133be4f5017f41622f9 to your computer and use it in GitHub Desktop.
Save afriza/f857c2da90ab3133be4f5017f41622f9 to your computer and use it in GitHub Desktop.
List all IPs of all running docker containers
#! /usr/bin/env -S sh
# Reference: https://stackoverflow.com/a/36883565/109747
docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' $(docker ps -aq)
#! /usr/bin/env -S sh
# Reference: https://stackoverflow.com/a/63023383/109747
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}} %tab% {{.Name}}' $(docker ps -aq) \
| sed 's#%tab%#\t#g' | sed 's#/##g' | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment