Skip to content

Instantly share code, notes, and snippets.

@phuysmans
Created December 2, 2019 14:49
Show Gist options
  • Save phuysmans/22bd0b9a667e40db6e255174e2eadf99 to your computer and use it in GitHub Desktop.
Save phuysmans/22bd0b9a667e40db6e255174e2eadf99 to your computer and use it in GitHub Desktop.

Revisions

  1. phuysmans created this gist Dec 2, 2019.
    17 changes: 17 additions & 0 deletions docker-container-age
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/usr/bin/env bash

    set -eo pipefail

    CONTAINER=$1
    NOW=$(date +%s)

    if [ "$(docker ps -a -q -f name=${CONTAINER})" ]; then
    STARTED_AT=$(docker inspect -f "{{.State.StartedAt}}" ${CONTAINER})
    STARTED=$(date -d "${STARTED_AT}" +%s)
    DIFF=$(( (${NOW} - ${STARTED}) / 60))
    echo ${DIFF}
    else
    echo 0
    fi

    exit 0