Docker container alerts on your phone
Docker crashes, out-of-memory kills and failed health checks reach your phone through PushPiper, free for 10,000 messages a month on 10 devices. A small bash script streams Docker events to the API, and iPhones from iOS 16.4 work without an App Store install.
How container events tell you when something breaks
Docker tracks state changes internally and exposes them through a real-time event stream. Instead of running continuous polling scripts that run docker ps every few seconds to look for missing containers, you can attach directly to the daemon's event pipeline. It streams everything.
Filtering keeps your log traffic minimal and prevents unnecessary processing on busy hosts, which lets you narrow the feed down strictly to termination and health check failures without running extra background daemons. You set --filter type=container so the daemon ignores image downloads, network creation, and volume mounts. Adding --filter event=die, --filter event=oom, and --filter event=health_status catches container failures immediately. Specifying health_status without a colon matches every health change event Docker emits, whether the check passes or fails.
What the watcher catches and ignores
The table below compares the Docker events our watcher processes against what they mean and the alert text sent to your phone.
| Event | Means | Alert text |
|---|---|---|
| die | The container's main process exited | name stopped with exit code N |
| oom | The kernel killed it for memory | name ran out of memory |
health_status: unhealthy | Its health check is failing | name is unhealthy |
health_status: healthy | Back to healthy | Skipped |
When a container runs out of memory, the Linux kernel kills the container process and emits an oom event before triggering termination. The script picks up this distinct action immediately, so you won't have to guess whether a dead container was terminated by a user or dropped by an out-of-memory exception.
For health checks, containers cycle between healthy and unhealthy based on your custom health check instructions. The watcher skips healthy events entirely, which prevents routine recovery checks from cluttering your phone's notification tray. When a health check fails, Docker outputs health_status: unhealthy instead, prompting an instant alert with the container name. That keeps your phone silent until an actual failure demands attention.
Setting up the bash watcher script
To get started, create the watcher script on your host system. You'll need an active PushPiper account to receive the notifications. You can Open PushPiper and sign up free in a browser, then copy your user key and create an application token.
- Save the watcher script to
/usr/local/bin/docker-pushpiper.sh. - Make the file executable with
chmod +x /usr/local/bin/docker-pushpiper.sh. - Replace
APP_TOKENin the script with your 30-character application token from PushPiper. - Replace
USER_KEYwith your 30-character PushPiper user key.
The script formats incoming events into piped strings, splits the container name, action, and exit code, and then routes them through curl. The message payload uses priority 1, which means it bypasses PushPiper quiet hours on your device.
#!/usr/bin/env bash
docker events \
--filter type=container \
--filter event=die \
--filter event=oom \
--filter event=health_status \
--format '{{.Actor.Attributes.name}}|{{.Action}}|{{.Actor.Attributes.exitCode}}' |
while IFS='|' read -r name action code; do
case "$action" in
"health_status: healthy") continue ;;
die) message="$name stopped with exit code $code" ;;
oom) message="$name ran out of memory" ;;
*) message="$name is ${action#health_status: }" ;;
esac
curl -s -o /dev/null https://api.pushpiper.com/1/messages.json \
--form-string "token=APP_TOKEN" \
--form-string "user=USER_KEY" \
--form-string "title=Docker on $(hostname)" \
--form-string "message=$message" \
--form-string "priority=1"
donePushPiper limits messages to 1,024 characters and limits API calls to 600 requests a minute per app token. The short notification strings built by this script stay well inside both boundaries. If you want to customize the curl call or pass extra fields like custom sounds, take a look at the API reference or review our guide on push notifications from shell scripts and cron jobs.
Running the watcher as a systemd service
A monitoring script does you no good if it stops running after you log out of your terminal session. To keep it persistent across system reboots, manage the script with systemd.
- Create a new service file at
/etc/systemd/system/docker-pushpiper.service. - Paste the unit configuration shown below into the file.
- Run
systemctl daemon-reloadto register the new unit. - Enable and start the service with
systemctl enable --now docker-pushpiper.service.
[Unit]
Description=Docker container alerts to PushPiper
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/local/bin/docker-pushpiper.sh
Restart=always
[Install]
WantedBy=multi-user.targetThe unit file sets Restart=always, so systemd will automatically bring the watcher back up if the bash process exits or if the Docker daemon restarts underneath it. The After=docker.service and Requires=docker.service directives guarantee that systemd never starts the watcher before Docker's daemon socket exists.
User permissions and socket access
By default, the Docker daemon binds to a Unix socket owned by root. Because this systemd unit runs as root by default, it has access to /var/run/docker.sock without additional configuration. If you configure the service to run under a dedicated unprivileged system user instead, you must add that user to the docker group on the host so it can interact with the socket.
Testing alerts and handling expected shutdowns
Once the systemd service is active, verify that notifications reach your device. You can run a quick test container that exits with an error code:
docker run --rm busybox sh -c "exit 42"Your phone should receive a notification stating that the container stopped with exit code 42.
Docker doesn't differentiate between a container crash and a graceful shutdown when firing the die event. In both situations, the main container process terminates, and Docker dispatches the exit code. If you run docker stop, the container typically exits with code 0 or 143, triggering a notification just like an unexpected crash would.
If your team manages a high volume of containers and needs higher limits, PushPiper pricing offers Pro and Team tiers. The Free plan covers 10,000 messages a month forever with no credit card required, which is plenty of headroom for homelabs and small production setups.
Sources
Questions and answers
Does PushPiper have a native mobile app in the app stores?
PushPiper delivers notifications through web push instead of native App Store or Play Store apps. On an iPhone or iPad running iOS 16.4 or later, open the site in Safari and tap Add to Home Screen to install it.
Can container alerts break through Apple Do Not Disturb?
No, PushPiper cannot send iOS critical alerts that break through Do Not Disturb or Focus modes. Setting an alert to priority 1 ignores PushPiper quiet hours, but it cannot override system-level device silencers.
What permissions does the watcher script need to read events?
The script requires read access to the Docker daemon socket. You can run the script as root or add your non-root system user to the docker group on the host.
What happens when I hit the monthly message limit?
When you reach your monthly limit of 10,000 messages on the Free plan, the API returns an HTTP 429 error and stops delivering notifications. Your quota resets automatically on the first day of the month at 00:00 UTC.