First create a bash script that sends mail-send_mail.sh:
#!/bin/Bashcurl-S--user'api:key-xxxxxxxxxxxxx'https://api.mailgun.net/v3/xxxxxxx/messages \-F from='Support <[email protected]>' -F to='xxx <[email protected]>' -F subject="$mail _subject" -F text="$mail _text"
The email here is mailgun and can be replaced by a different email provider.
Then create a script to check Docker status-check_docker_status.sh:
!/bin/bashexport mail_subject="Docker running status exception !" " now = 'date +%y-%m-%d#%h:%m:%S ' export mail_text='Docker found in $now stopped running " PSgrepIDawk'{if (! ( /up/)) {System ("/home/xxx/send_mail.sh")}}'
Then remember to add the send_mail.sh and check_docker_status.sh scripts to the executable properties.
Last added to Crontab:
Crontab-eXX * * * * */home/xxx/check_docker_status. SH
The system checks the Docker status at 0 minutes per hour and sends a message to the specified mailbox once it is not in the up state.
Done
Docker: Check the running status of Docker container and mail alerts periodically