Created
October 18, 2019 14:49
-
-
Save renatoassis01/03e1156caaaa8792abfe766ee9398f40 to your computer and use it in GitHub Desktop.
stop container after
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
STOP_CONTAINER_AFTER=600 | |
containers=$(docker container ls -q) | |
for container in $containers; do | |
started_at="$(docker container inspect -f {{.State.StartedAt}} $container)" | |
date_container_run=$(($(date +%s) - $(date --date="${started_at}" +%s))) | |
if [ $date_container_run -gt $STOP_CONTAINER_AFTER ] | |
then | |
docker container stop "$container" | |
echo "STOP container ID $container" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment