STATUS ÜBERPRÜFEN
I AM LISTENING TO
|

Day 7: NTFY Self-Hosted Push Notification Service – 7 Days of Docker

16. Februar 2025
.SHARE

Table of Contents

Introduction

ntfy is a powerful, self-hosted push notification service that allows you to send messages to your devices via HTTP, MQTT, or WebSockets. Running ntfy in a Docker container makes deployment and management easy, ensuring a lightweight and scalable notification system.

This guide walks you through setting up ntfy with Docker, configuring it, and making the most of its features.

Prerequisites

Before we begin, ensure you have:

  • Docker installed on your machine (Get Docker)
  • (Optional) Docker Compose for easier configuration

1: Pull the ntfy Docker Image

The official ntfy image is available on Docker Hub. To pull it, run:

docker pull binwiederhier/ntfy

This command downloads the latest ntfy image to your system.

2: Run ntfy as a Docker Container

A simple way to start ntfy is by running the following command:

docker run -d \
  --name ntfy \
  -p 80:80 \
  binwiederhier/ntfy serve

This starts ntfy as a background service (-d), mapping the container’s port 80 to the host’s port 80.

You can now access ntfy by visiting http://localhost.

3: Persisting Data with a Volume

To keep your settings and messages after a container restart, you should mount a volume:

docker run -d \
  --name ntfy \
  -p 80:80 \
  -v ntfy_data:/var/lib/ntfy \
  binwiederhier/ntfy serve

This ensures that all data is stored in a persistent volume called ntfy_data.

4: Custom Configuration

For advanced settings, create a custom config file:

  1. Create a directory for ntfy:
   mkdir -p ~/ntfy
  1. Create a server.yml file with custom settings:
   listen-http: ":8080"
   base-url: "https://yourdomain.com"
   auth-file: "/var/lib/ntfy/user.db"
  1. Run ntfy with the custom configuration:
   docker run -d \
     --name ntfy \
     -p 8080:8080 \
     -v ~/ntfy:/var/lib/ntfy \
     binwiederhier/ntfy serve

This mounts your local ~/ntfy directory as the ntfy storage location, allowing persistent configuration.

5: Sending Notifications

Once ntfy is running, you can send notifications using cURL:

curl -d "Hello, ntfy!" http://localhost/mytopic

Or using the ntfy CLI:

echo "Hello, ntfy!" | ntfy publish mytopic

6: Running with Docker Compose (Optional)

That is how I currently use it.

portalZINE.DE | portalzine nmn development meets creativity blog 36

Using Docker Compose simplifies container management. Create a docker-compose.yml file:

version: '3'
services:
  ntfy:
    image: binwiederhier/ntfy
    container_name: ntfy
    command:
      - serve
    environment:
      - TZ=UTC    # optional: set desired timezone
    #user: UID:GID # optional: replace with your own user/group or uid/gid
    volumes:
      - /var/cache/ntfy:/var/cache/ntfy
      - /etc/ntfy:/etc/ntfy
    ports:
      - 3003:80
    healthcheck: # optional: remember to adapt the host:port to your environment
        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

Start the service with:

docker-compose up -d

Thoughts

Running ntfy with Docker is an efficient way to manage notifications on your own infrastructure. Whether you’re using it for server monitoring, IoT notifications, or personal alerts, ntfy provides a lightweight and flexible solution.

There are also nice apps for Desktop and Mobile.

I am using it actively for all my CRON notifications and much more … https://portalzine.de/wordpress-cron-wp-cli-ntfy

Let’s Talk!

Looking for a reliable partner to bring your project to the next level? Whether it’s development, design, security, or ongoing support—I’d love to chat and see how I can help.

Get in touch,
and let’s create something amazing together!

RELATED POSTS

You can SSH into a server and move files around with raw scp and sftp commands, but the moment you manage more than a couple of machines you start wishing for something friendlier — without giving up the terminal. That’s exactly the gap the new wave of TUI clients fills: full-screen file explorers and SSH […]

Picking a color picker sounds like a five-minute decision, and then you open a dependency tree full of jQuery, React wrappers and „lightweight“ libraries that weigh more than your whole app. If you just need a solid color picker that adds nothing to your bundle except the picker itself, you’ve come to the right place. […]

Markdown is perfect right up until a second person touches it. On your own, a folder of .md files is the best documentation system ever invented. Add four colleagues and suddenly you’ve got three different heading styles, a README that links to a domain that expired in 2023, and Steve, who writes every sentence in […]

Alexander

I am a full-stack developer. My expertise include:

  • Server, Network and Hosting Environments
  • Data Modeling / Import / Export
  • Business Logic
  • API Layer / Action layer / MVC
  • User Interfaces
  • User Experience
  • Understand what the customer and the business needs


I have a deep passion for programming, design, and server architecture—each of these fuels my creativity, and I wouldn’t feel complete without them.

With a broad range of interests, I’m always exploring new technologies and expanding my knowledge wherever needed. The tech world evolves rapidly, and I love staying ahead by embracing the latest innovations.

Beyond technology, I value peace and surround myself with like-minded individuals.

I firmly believe in the principle: Help others, and help will find its way back to you when you need it.