Skip to content

Ntfy

Docker Compose

version: "3.7"

services:
  ntfy:
    container_name: ntfy
    image: binwiederhier/ntfy
    ports:
      - '80:80'
    command:
      - serve
    environment:
      - TZ=UTC    # optional: set desired timezone
    volumes:
      - '${HOME}/docker-data/ntfy/config:/etc/ntfy'
      - '${HOME}/docker-data/ntfy/config/user.db:/var/lib/ntfy/user.db'
    healthcheck: # optional: remember to adapt the host:port to your environment
        test: ["CMD-SHELL", "wget -q --tries=1 http://172.18.0.1:80/v1/health -O - | grep -Eo '\"healthy\"\\s*:\\s*true' || exit 1"]
        interval: 60s
        timeout: 10s
        retries: 3
        start_period: 40s
    restart: unless-stopped

networks:
  default:
    name: networkname
    external: true

Make sure user.db and server.yml exist beforehand

server.yml

base-url: 'https://ntfy.example.com'
upstream-base-url: 'https://ntfy.sh'
behind-proxy: true
auth-file: '/var/lib/ntfy/user.db'
auth-default-access: 'deny-all'
enable-login: true

Adding an Admin

sudo docker exec -it ntfy /bin/ash

ntfy user add --role=admin someUser

Add a Token to a user by default it will make it never to expire:

ntfy token add someUser

token xxx created for user someUser, never

To list out all users: ntfy user list

Authenitcating

Authenticating with User and Password

curl \
-u someUser:password \
-d "Some random noti" \
https://ntfy.example.com/sometopic

Authenticating with Access Tokens (Bearer)

curl \
-H "Authorization: Bearer tokenhere" \
-d "Some random noti" \
https://ntfy.example.com/sometopic

You can find different fields you can use here

Alternatively, you can use Basic Auth to send the access token. When sending an empty username, the basic auth password is treated by the ntfy server as an access token.

curl \
-u :tokenhere \
-d "Some random noti" \
https://ntfy.example.com/sometopic

A more in depth example:

curl \
-u :tokenhere \
-H "Title: Unauthorized access detected" \
-H "Priority: urgent" \
-H "Tags: warning,skull" \
-d "Remote access to phils-laptop detected. Act right away." \
ntfy.example.com/someTopic

Query Parameter

Generate value of auth parameter, encode the value of Authorization header user and password:

echo -n "Basic `echo -n 'someUser:password' | base64`" | base64 | tr -d '='

Access Tokens:

echo -n "Bearer someToken" | base64 | tr -d '='

Using Auth query parameter with either generated value using user & password or access token

curl \
-d "Some random noti" \
"https://ntfy.example.com/someTopic?auth=xxx"

Webhooks

Make a GET request

curl "https://ntfy.example.com/someTopic/publish?message=Some+Message&auth=xxx"

HTTP PUT/POST

curl \
-u :someToken \
-H "Title: Unauthorized access detected" \
-H "Priority: urgent" \
-H "Tags: warning,skull" \
-d "Remote access to phils-laptop detected. Act right away." \
https://ntfy.example.com/someTopic

Publish as JSON

curl https://ntfy.example.com/ \
-H "Authorization: Bearer someToken" \
-d '{
  "topic": "someTopic",
  "message": "Disk space is low at 5.1 GB",
  "title": "Low disk space alert",
  "tags": ["warning","cd"],
  "priority": 4,
  "attach": "https://filesrv.lan/space.jpg",
  "filename": "diskspace.jpg",
  "click": "https://homecamera.lan/xasds1h2xsSsa/",
  "actions": [{ "action": "view", "label": "Admin panel", "url": "https://filesrv.lan/admin" }]
}'

More Examples can be found in ntfy docs here