Skip to content

Instantly share code, notes, and snippets.

@renatoassis01
Created October 18, 2019 14:49
Show Gist options
  • Save renatoassis01/03e1156caaaa8792abfe766ee9398f40 to your computer and use it in GitHub Desktop.
Save renatoassis01/03e1156caaaa8792abfe766ee9398f40 to your computer and use it in GitHub Desktop.
stop container after
#! /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