Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active April 14, 2022 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knbknb/da4a5301a7a408aa5602183e52d9e831 to your computer and use it in GitHub Desktop.
Save knbknb/da4a5301a7a408aa5602183e52d9e831 to your computer and use it in GitHub Desktop.
Local docker containers as JSON
# 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