Skip to content

Instantly share code, notes, and snippets.

@exhuma
Created September 5, 2024 07:35
Show Gist options
  • Save exhuma/96f75568b39a49729cda26c3c4115457 to your computer and use it in GitHub Desktop.
Save exhuma/96f75568b39a49729cda26c3c4115457 to your computer and use it in GitHub Desktop.
#!/bin/bash
# -----------------------------------------------------------------------------
# This script extracts the path of the devcontainer config-file from
# docker-events.
#
# This helps in identifying who has started a container if the container-name
# does not itself include any indication.
#
# This can be used to determine if a container can be safely stopped/removed
#
# It takes one argument: The container-name
# -----------------------------------------------------------------------------
docker events \
--filter="container=${1}" \
--since="$(date --date '3 weeks ago' -Iseconds)" \
--until="$(date -Iseconds)" \
--format=json \
| jq -c '{status: (.status | split(" ")[0]), config: .Actor.Attributes."devcontainer.config_file"}' \
| sort \
| uniq -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment