LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Thursday, April 24, 2025

Setting Up ntfy for Push Notifications

0 comments

In an era where real-time communication is critical, push notifications are a great way to get instantly alerted about events, server activities, or updates. ntfy is a lightweight, open-source notification service that allows you to send push messages to your phone or desktop using simple tools like curl, Python, or shell scripts.

In this guide, I’ll walk you through installing and running ntfy using Docker on a self-hosted server. By the end, you’ll have your own fully functional push notification service running under your control.

Why Use ntfy

  • Self-hostable
  • Privacy-respecting (no need to rely on third-party services)
  • Integrates easily with mobile and desktop apps
  • Works well with bash, Python, curl, and more

Docker Setup for ntfy

We'll run the ntfy server in Docker using docker-compose. Here’s a step-by-step guide:


Step 1: Create Directory Structure

mkdir -p docker/ntfy-server
cd docker/ntfy-server

Step 2: Create the docker-compose.yml File

Open nano or your preferred editor:

nano docker-compose.yml

And paste the following:

services:
  ntfy:
    image: binwiederhier/ntfy
    container_name: ntfy-server
    command:
      - serve
    environment:
      - TZ=Asia/Kolkata
    volumes:
      - ./var/cache/ntfy:/var/cache/ntfy
      - ./etc/ntfy:/etc/ntfy
    ports:
      - 8150:80
    healthcheck:
      test: ["CMD-SHELL", "wget -q --tries=1 http://localhost:8150/v1/health -O - | grep -Eo '\"healthy\"\\s*:\\s*true' || exit 1"]
      interval: 60s
      timeout: 10s
      retries: 3
      start_period: 40s
    restart: unless-stopped

This configuration maps port 8150 to ntfy’s default port and stores cache and config files locally for persistence.

Step 3: Start the Server

sudo docker compose up -d && sudo docker compose logs -f

Your ntfy server is now running at:


Using ntfy to Send Notifications

From Command Line

curl -d "Backup completed successfully" http://your-server-ip:8150/backup-status

No comments:

Post a Comment