How to Self-Host ntfy With Docker for Home Server Alerts

17 min read

,
Terminal running a curl command that publishes Hi there to the ntfy topic phil_alerts, with the matching ntfy desktop notification popping up above it

When a backup fails at 2 AM or the UPS switches to battery, an email can sit unread until lunch. A push notification on your phone is much harder to miss, and ntfy is one of the simplest ways to get one: any script, cron job or app that can make an HTTP request can ping your phone with a single curl line.

Diagram of how an ntfy alert reaches a phone: a script, cron job or app publishes with a single HTTP request using an alerts token, to a topic on your ntfy server such as homelab-backup, then the ntfy app. Only users you grant access can read the topic. Android uses instant delivery over a direct connection. iPhone alerts are relayed through ntfy.sh, which receives only a message ID and a SHA-256 hash of the topic URL, so the alert text never leaves your server
Image: Techzei

The public ntfy.sh server works without an account, but anyone who guesses your topic name can read your alerts, and you share its rate limits. Self-hosting ntfy with Docker fixes both. You get password-protected topics, a separate access token for every machine, and a server that keeps working for your local network even if ntfy.sh has a bad day. iPhones still get instant alerts, relayed through ntfy.sh without it ever seeing the message text.

A private server takes about half an hour: Docker Compose for the server, users and tokens to lock it down and HTTPS in front. After that, each alert source most home servers care about, Proxmox VE, Uptime Kuma, NUT power events and restic backups, needs only a few minutes.

ntfy.sh or your own ntfy server?

Both use the same apps and the same publishing syntax, so moving later is mostly a matter of changing a URL. The differences are about privacy, limits and who keeps the server running.

Public ntfy.shSelf-hosted ntfy
Who can read a topicAnyone who knows the topic nameOnly users you grant access
AccountsOptionalYou create users and tokens
Daily messagesSubject to the public service’s rate limitsSet by your own limits
Attachment size2 MB per file15 MB per file by default
Android deliveryFirebase (Google Play app)Instant delivery over a direct connection
iPhone deliveryNative pushPush via a configured relay, such as ntfy.sh
UpkeepNoneUpdates, backups and HTTPS are on you

If you only send a couple of alerts a day and are happy with a long random topic name, ntfy.sh is fine. Once alerts start carrying hostnames, VM names and backup details, a private server with authentication is the better home for them.

What you need before you start

  • A Linux machine that is always on with Docker and the Docker Compose plugin. A mini PC, a Raspberry Pi, a VM or an LXC container all work; the official image is built for amd64, armv6, armv7 and arm64. If you are still planning the hardware, our home server or NAS guide covers the basics.
  • A hostname such as ntfy.example.com that points to the machine, plus a reverse proxy for HTTPS. Caddy is used in this guide because it gets certificates automatically.
  • The ntfy app on your phone: Android from Google Play or F-Droid, iPhone from the App Store. The web app is built into the server.
  • About 30 minutes, plus a few minutes for each service you connect.

ntfy does not need a database server. It keeps users and its message cache in small SQLite files, so the whole setup lives in one folder that is easy to back up.

Step 1: Create the folders and server.yml

The Docker image does not ship with a config file, so you create one and mount it into the container. Keeping config and data in two folders makes the later CLI commands and backups simpler.

mkdir -p ~/ntfy/etc ~/ntfy/data
cd ~/ntfy
nano etc/server.yml

Paste this config and change the base-url to your own hostname:

# ~/ntfy/etc/server.yml
base-url: "https://ntfy.example.com"
listen-http: ":80"

# Keep messages on disk so phones can catch up after a restart
cache-file: "/var/lib/ntfy/cache.db"
cache-duration: "24h"
attachment-cache-dir: "/var/lib/ntfy/attachments"

# Private server: nobody can read or write without an account
auth-file: "/var/lib/ntfy/user.db"
auth-default-access: "deny-all"
enable-login: true

# Running behind Caddy or another reverse proxy
behind-proxy: true

# Lets the iOS app get instant notifications
upstream-base-url: "https://ntfy.sh"

A few of these lines matter more than they look. base-url must be the exact public URL you will type into the apps, because attachments and iPhone push both depend on it. auth-default-access: "deny-all" turns the server from open to private, which is the setting ntfy’s own docs recommend for a private instance. Without cache-file, ntfy keeps messages in memory for 12 hours and loses them on every restart; here they are stored on disk for 24 hours instead. behind-proxy tells ntfy to read the real client IP from the X-Forwarded-For header; without it, every visitor looks like the proxy and shares one rate limit.

Step 2: Start ntfy with Docker Compose

Create ~/ntfy/compose.yaml. This is based on the official Compose example, including its health check, with the two folders from Step 1 mounted:

services:
  ntfy:
    image: binwiederhier/ntfy
    container_name: ntfy
    command:
      - serve
    environment:
      - TZ=UTC    # change to your own time zone
    volumes:
      - ./etc:/etc/ntfy
      - ./data:/var/lib/ntfy
    ports:
      - 8080:80
    healthcheck:
      test: ["CMD-SHELL", "wget -q --tries=1 http://localhost:80/v1/health -O - | grep -Eo '\"healthy\"\\s*:\\s*true' || exit 1"]
      interval: 60s
      timeout: 10s
      retries: 3
      start_period: 40s
    restart: unless-stopped
    init: true
docker compose up -d
docker compose ps
curl -s http://localhost:8080/v1/health

The health endpoint should answer {"healthy":true,...}, and docker compose ps should show the container as healthy after a minute. Port 8080 on the host maps to ntfy’s port 80 inside the container. If Caddy runs on the same machine and nothing else needs direct access, change the mapping to 127.0.0.1:8080:80 so ntfy is only reachable through the proxy.

ntfy web app showing the phil_alerts topic with a notification titled Alert: Spring is coming, a sunflower image attachment and the subscribed topics list on the left
Image: ntfy

Opening http://server-ip:8080 in a browser now shows the ntfy web app. With deny-all set, it will not let you subscribe to anything until you create a user.

Step 3: Create users and topic permissions

ntfy has two roles. An admin can read and write every topic. A user has no access until you add access control entries for specific topics or wildcard patterns. The ntfy user and ntfy access commands edit the user database directly, so run them inside the container:

# Your own account for the phone and web app (prompts for a password)
docker exec -it ntfy ntfy user add --role=admin yourname

# A publish-only account for servers and scripts
docker exec -it ntfy ntfy user add alerts
docker exec -it ntfy ntfy access alerts 'homelab-*' write-only

# Check the result
docker exec -it ntfy ntfy access

The alerts account can publish to any topic that starts with homelab- but cannot subscribe to anything, so a leaked credential from one machine cannot be used to read your other alerts. Topic names may use letters, numbers, underscores and dashes, up to 64 characters.

ntfy can also define users, permissions and tokens declaratively in server.yml with auth-users, auth-access and auth-tokens, using bcrypt password hashes from ntfy user hash. That suits people who rebuild containers often. Be careful with it: users that are removed from the config are deleted from the database on the next restart, including users you first created by hand and later added to the config.

Step 4: Give every service its own access token

Access tokens save you from putting a password into every script. Each user can have up to 60 tokens, each with a label and an optional expiry. One important limit from the docs: a token currently grants full access to its user account, not to a single topic. That is why the tokens below belong to the write-only alerts user rather than your admin account.

Graphic of ntfy access control on a private server: auth-default-access is deny-all. An admin account for the phone and web app can read and write every topic, so one login covers all of them. The alerts user is a publish-only account for servers and scripts, with write-only access to homelab-* topics, and cannot subscribe, so a leaked credential cannot be used to read other alerts. Each service gets its own access token labelled proxmox, uptime-kuma, nut-ups or restic, belonging to the write-only alerts user. A token currently grants full access to its user account, not to a single topic, which is why these tokens are not created on the admin account
Image: Techzei
docker exec -it ntfy ntfy token add --label="proxmox" alerts
docker exec -it ntfy ntfy token add --label="uptime-kuma" alerts
docker exec -it ntfy ntfy token add --label="nut-ups" alerts
docker exec -it ntfy ntfy token add --label="restic" alerts

docker exec -it ntfy ntfy token list alerts

Each command prints a token that starts with tk_. Copy each one into a password manager next to its label. If a machine is retired or compromised, remove just that token with ntfy token remove alerts tk_... and everything else keeps working. Because enable-login is on, you can also create and delete tokens for your own account from the Account page of the web app.

A simple layout that scales well:

SourceTopicToken labelTypical priority
Proxmox VEhomelab-pveproxmoxHigh for errors
Uptime Kumahomelab-uptimeuptime-kumaUrgent when a monitor goes down
NUT (UPS)homelab-upsnut-upsUrgent for low battery
restic backupshomelab-backupresticHigh on failure

Separate topics let you mute or tune each source on the phone. Your admin account can read all of them, so one login on the phone covers everything.

Step 5: Put ntfy behind HTTPS

Basic auth only encodes the password, it does not encrypt it, so ntfy’s docs say to use HTTPS on a self-hosted server. With Caddy installed on the same machine, two lines are enough, and Caddy also handles the WebSocket connections the apps use:

# /etc/caddy/Caddyfile
ntfy.example.com {
    reverse_proxy 127.0.0.1:8080
}
sudo systemctl reload caddy
curl -s https://ntfy.example.com/v1/health

If you use nginx or Apache instead, copy the proxy config from ntfy’s docs, which forwards the Upgrade and Connection headers for WebSockets. Caddy needs ports 80 and 443 reachable from the internet to get a public certificate. If you would rather not open ports at all, you can keep ntfy on your LAN or a VPN such as Tailscale; just remember that your phone then needs that VPN connected to fetch messages when you are away from home.

Now confirm that the server really is private. An anonymous publish should be refused:

curl -i -d "should fail" https://ntfy.example.com/homelab-test

A 401 or 403 response means the deny-all rule is working.

Step 6: Subscribe on Android, iPhone and the web

On Android, tap the plus button, enter a topic such as homelab-pve, tick Use another server and enter https://ntfy.example.com. The app will ask for your username and password because the topic is protected. You can also set your server as the default in Settings so you do not have to tick the box for every topic.

ntfy Android app Subscribe to topic dialog with a topic name field, the Use another server option ticked and a server URL field below it
Image: ntfy

Self-hosted topics on Android use instant delivery, a direct connection kept open by a foreground service, so messages arrive even when the phone is in doze mode. The trade-off is a permanent notification, which you can hide by long-pressing it and turning off the Subscription Service channel. The Google Play app only uses Firebase for ntfy.sh, and the F-Droid build never uses it.

On the iPhone, add the same server URL and topic in the ntfy app and sign in. iOS does not allow apps to hold a connection open in the background, which is why upstream-base-url is in the config. When you publish a message, your server sends ntfy.sh only a poll request containing the message ID and a SHA-256 hash of the topic URL. ntfy.sh passes that to Apple’s push service, and your phone then fetches the real message from your own server. The relay does not receive the alert text. The phone retrieves the text directly from your server. If the phone cannot reach your server in time, it shows a generic “New message” notification instead. Without the upstream setting, iPhone notifications still arrive eventually, but they can be hours late, or 20 to 30 minutes late while you are using the phone.

For the web app, open https://ntfy.example.com, log in and add the topics. It works as a dashboard for recent alerts on a desktop.

Step 7: Send a test notification

Publishing is a single HTTP request. The message goes in the body, and headers set the title, priority and tags. Use one of the alerts tokens:

curl \
  -H "Authorization: Bearer tk_your_token_here" \
  -H "Title: Test from the home server" \
  -H "Priority: high" \
  -H "Tags: heavy_check_mark,homelab" \
  -d "ntfy is working" \
  https://ntfy.example.com/homelab-test

Tags that match an emoji short code, such as warning, rotating_light or heavy_check_mark, become an emoji in front of the title. Other tags are listed under the message, which is handy for hostnames.

ntfy Android app showing a topic list of notifications, including Backup of mailsrv13 failed with a warning emoji and tags mailsrv13 and daily-backup
Image: ntfy

Priority decides how loudly the phone reacts, so it is worth using deliberately:

PriorityValueWhat the phone does
max / urgent5Long vibration bursts, sound and a pop-over notification
high4Long vibration, sound and a pop-over
default3Short vibration and sound
low2Silent, shows only when you pull down the notification shade
min1Silent, listed under other notifications

On Android, each priority has its own notification channel, so you can give urgent alerts a different sound or let them override Do Not Disturb. Keep messages under 4,096 bytes; anything longer is treated as an attachment.

Step 8: Send Proxmox VE alerts to ntfy

Proxmox VE 8.3 and newer include a generic webhook notification target, and the admin guide uses ntfy as its first example. In the web UI, go to Datacenter > Notifications, click Add under Notification Targets and choose Webhook. Fill it in like this:

  • Method: POST
  • URL: https://ntfy.example.com/homelab-pve
  • Headers: Authorization with the value Bearer {{ secrets.token }}, Title with {{ title }}, Tags with {{ severity }}, and Markdown with yes
  • Body: {{ message }}
  • Secrets: a secret named token containing your proxmox token

Secrets are stored in /etc/pve/priv/notifications.cfg, which only root can read, so the token does not appear in the normal config file. Save the target and use the test button to check that a message reaches your phone.

A target does nothing until a matcher sends events to it. Under Notification Matchers, add a matcher, open the Match Rules tab and add a Match Severity rule. Then pick the ntfy target under Targets to notify.

Proxmox VE Edit Notification Matcher dialog on the Match Rules tab, with a rule tree matching severity warning, error and unknown, a calendar of Monday to Friday 8 to 16 and the field type equal to vzdump
Image: Proxmox

Which severities you match is the main decision. Backup failures, failed storage replication and node fencing arrive as error, while successful backups and available updates are info. Include unknown as well: mail that system daemons such as smartd send to root is turned into a system-mail event with unknown severity, so a warning-and-error rule alone would silently drop disk health warnings. Also check each backup job’s notification mode. It must use the global notification system, not the legacy sendmail mode, or the matcher is ignored for that job.

Step 9: Connect Uptime Kuma

Uptime Kuma has ntfy built in. Go to Settings > Notifications > Setup Notification and choose ntfy as the notification type. Enter homelab-uptime as the topic and https://ntfy.example.com as the Server URL, without the topic on the end. Set the Authentication Method to Access Token and paste the uptime-kuma token.

Uptime Kuma Setup Notification dialog with ntfy selected as the notification type, fields for friendly name, ntfy topic, server URL and priority, and switches for Default enabled and Apply on all existing monitors
Image: ntfy

Recent versions have two priority fields: a normal priority and a separate Priority for DOWN-events. Setting the normal one to 3 and DOWN to 5 makes outages loud and recoveries quiet. Click Test, then turn on Default enabled and Apply on all existing monitors if you want every monitor to use it. Our Uptime Kuma setup guide covers the monitors themselves, including Push monitors that warn you when a backup job never runs.

One caution: do not run Uptime Kuma and ntfy on the same machine and expect to hear about that machine going down. Put the monitor somewhere else, or add an external check that watches the ntfy server.

Step 10: Send NUT power alerts

If you followed our guide to set up Network UPS Tools, your upssched script already posts to ntfy. Point it at your own server and add the token:

#!/bin/sh
# /usr/local/bin/ups-ntfy
TOPIC="https://ntfy.example.com/homelab-ups"
TOKEN="tk_your_nut_ups_token"

send() {
  curl -s --max-time 10 \
    -H "Authorization: Bearer $TOKEN" \
    -H "Title: $1" -H "Priority: $2" -H "Tags: $3" \
    -d "$4" "$TOPIC" > /dev/null
}
# keep the case block for onbatt, online, lowbatt and the other events as before
# upssched runs as the NUT user; on Debian and Ubuntu its group is nut
chown root:nut /usr/local/bin/ups-ntfy
chmod 750 /usr/local/bin/ups-ntfy
systemctl restart nut-monitor.service

The token now sits inside the script, so the permissions above keep it readable only by root and the NUT service rather than every user on the machine.

Power alerts have a catch that other alerts do not. The ntfy server, your router and your internet connection all need power for the message to get out. Run ntfy on a machine that is on the UPS and shuts down last, and keep the router on battery too. The --max-time option stops a dead network from delaying the shutdown script.

Step 11: Get restic backup failure alerts

restic has no notification system of its own, but it returns clear exit codes: 0 for success, 3 when some files could not be read, and other non-zero codes for failures such as a locked repository or a wrong password. If your backups run from a systemd service, the cleanest approach is a small alert unit that systemd starts whenever the backup unit fails.

# /etc/systemd/system/ntfy-failure@.service
[Unit]
Description=Send an ntfy alert when %i fails

[Service]
Type=oneshot
EnvironmentFile=/etc/ntfy-alert.env
ExecStart=/usr/bin/curl -s --max-time 15 -H "Authorization: Bearer ${NTFY_TOKEN}" -H "Title: %i failed on %H" -H "Priority: high" -H "Tags: warning" -d "Check the log with journalctl -u %i" ${NTFY_URL}
# /etc/ntfy-alert.env (chmod 600)
NTFY_URL=https://ntfy.example.com/homelab-backup
NTFY_TOKEN=tk_your_restic_token

Then attach it to the backup unit. Run sudo systemctl edit restic-backup.service and add these two lines in the editor that opens:

[Unit]
OnFailure=ntfy-failure@%n.service

systemd fills in %n with the failing unit’s name, so the alert title tells you exactly which job broke. Test it once with sudo systemctl start ntfy-failure@restic-backup.service.service; the doubled suffix is expected, because the instance name is the full unit name.

The same template works for any other systemd job, such as a ZFS scrub or a certificate renewal: add the OnFailure= line to that unit. If your backup is a cron job instead, chain the alert to the command, as ntfy’s own examples do: restic-backup.sh || curl ....

Because the alert goes out at high priority, Android shows it as a pop-over on top of whatever you are doing, so a failed backup is hard to miss.

Android pop-over notification with a warning emoji reading Unauthorized access detected and Remote access to phils-laptop detected. Act right away.
Image: ntfy

Failure alerts only tell you about runs that fail. A backup that never starts sends nothing, which is why a Push monitor in Uptime Kuma, waiting for a heartbeat after each successful run, is a good partner to this unit.

Keep the ntfy server healthy

  • Back up the data folder. ~/ntfy/data/user.db holds users, permissions and tokens; losing it means re-creating every token. Include ~/ntfy/etc too.
  • Update regularly. Run docker compose pull && docker compose up -d. ntfy releases often, and recent releases have included security fixes.
  • Use expiring tokens for temporary jobs. ntfy token add --expires=30d creates a token that stops working on its own.
  • Leave sign-up off. enable-signup is false by default, so nobody can create an account on your server from the web app.

Troubleshooting

  • 401 or 403 when publishing: the token is wrong, belongs to a user without write access to that topic, or the topic does not match the homelab-* pattern. Check with docker exec -it ntfy ntfy access alerts.
  • The app says connection error: the phone cannot reach base-url. Test the health URL in the phone’s browser, and check that your proxy passes WebSocket upgrades.
  • iPhone alerts are late or say only “New message”: confirm upstream-base-url is set and that the server can reach ntfy.sh. The URL in the app must match base-url exactly, because the hash sent upstream is calculated from it.
  • Every client shares one rate limit: behind-proxy: true is missing, so ntfy sees all traffic as coming from the proxy.
  • CLI commands report no auth file: make sure server.yml is mounted at /etc/ntfy inside the container and contains auth-file.
  • Messages vanish after a restart: cache-file is not set or the data folder is not mounted.

My take

ntfy hits a sweet spot for home servers. It is light enough to run on a Raspberry Pi, the publishing side is just curl, and Proxmox VE and Uptime Kuma already speak to it. Self-hosting is worth the extra half hour mainly for the access control: alerts stop being readable by anyone who guesses a topic name, and each machine gets a token you can revoke on its own.

The part to think about most is priority, not setup. If every successful backup buzzes your phone, you will start ignoring it within a week. Send failures, outages and power events at high or urgent priority, keep good news at low or not at all, and use a Push monitor to catch jobs that never ran.

FAQ

Is ntfy free to self-host?

Yes. The server, the Android app and the iOS app are open source, and the Docker image is free. ntfy.sh sells paid tiers for higher limits on the public server, but nothing on your own server requires a subscription.

Does the iOS relay send my alert text to ntfy.sh?

No. Your server forwards only a poll request with the message ID and a SHA-256 hash of the topic URL. The iPhone then downloads the actual message from your server. ntfy.sh never sees the title or body.

How long does ntfy keep messages?

By default, 12 hours in memory. With cache-file set, messages survive restarts for as long as cache-duration says, 24 hours in this guide. Attachments are deleted after 3 hours by default.

Can I use ntfy without exposing it to the internet?

Yes. It works fine on a LAN or over Tailscale. Servers on the same network can publish directly, and phones receive alerts whenever they can reach the server, so keep the VPN connected on your phone when you are away. iPhone push still needs your server to make outgoing connections to ntfy.sh, but nothing on the internet needs to reach your server.

About the author