container · docker · linux

docker: delete containers running for a long time

If you need to delete running containers based on their lifetime, this handy combination of commands can help you. It deletes all containers running for more than 2 hours.

HOUR=2
docker ps --filter "status=running" | grep hours | awk '{if ($4 >=$HOUR) print $1,"must be deleted"; system("docker rm -f " $1)}'

Advertisement

One thought on “docker: delete containers running for a long time

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s