Last active
April 14, 2022 15:59
-
-
Save knbknb/da4a5301a7a408aa5602183e52d9e831 to your computer and use it in GitHub Desktop.
Local docker containers as JSON
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
# How to get docker ps data in JSON format | |
# With curl version 7.40 and newer you can get data from the local unix socket, | |
# and docker always runs the remote api on docker.sock. | |
# ----- | |
# knbknb 2019, 2022 | |
# list of all running Docker containers, return names only | |
curl -s --unix-socket /var/run/docker.sock http://localhost/images/json | jq .[].Names | |
# list of all Docker images, return names (RepoTags) only | |
curl -s --unix-socket /var/run/docker.sock http://localhost/containers/json | jq -c .[].RepoTags | |
## construct a filter with jq | |
# Names/RepoTags of images _not_ containing "latest" in the inner RepoTags array | |
curl -s --unix-socket /var/run/docker.sock http://localhost/images/json | jq '. - map(select(.RepoTags[] | contains ("latest"))) | .[] .RepoTags[0]' | |
## found here: | |
## How to filter an array of objects based on values in an inner array with jq? | |
## https://stackoverflow.com/questions/26701538/how-to-filter-an-array-of-objects-based-on-values-in-an-inner-array-with-jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sources:
curl -> jq: How to get docker ps data in JSON format
How to filter an array of objects based on values in an inner array with jq?