0

For example, display only those containers that have been running for more than 10 minutes.

docker container ls -q --format '{{.Names}}' --filter status=running
Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
KaruseL
  • 3
  • 2

1 Answers1

0

First you need to get container creation date time then compare it with current date

#!/bin/bash    
# Date 1
container_date=$(docker inspect --format='{{.State.StartedAt}}' CONTAINER_NAME)
# Compute the seconds since epoch for date 1
t1=$(date --date="$container_date" +%s)

# Date 2 : Current date
current_date=$(date +%Y-%m-%d\ %H:%M:%S)
# Compute the seconds since epoch for date 2
t2=$(date --date="$current_date" +%s)

# Compute the difference in dates in seconds
let "tDiff=$t2-$t1"
# Compute the approximate hour difference
let "hDiff=$tDiff/3600"

echo "Approx hour diff b/w $container_date & $current_date= $hDiff"

reference link

behrooz razzaghi
  • 105
  • 1
  • 1
  • 8