计算容器运行至今多长时间

#!/bin/bash

container_name="xxxxx"echo $container_name
start_time_tmp=`sudo docker inspect --format='{{.State.StartedAt}}' $container_name`
now_time=`date '+%s'`
start_time=`date -d $start_time_tmp +%s`

run_time=`expr $now_time - $start_time`
echo $run_time
if [ $run_time -gt 1800 ]
then
        echo "容器至今运行超过半小时"
fi
原文地址:https://www.cnblogs.com/to-here/p/15224494.html