2026-12-04 · ntfy · docker · notifications · self-hosting
Self-Host ntfy with Docker: Push Notifications via HTTP
Run ntfy in Docker to self-host HTTP pub-sub push notifications. Covers compose, reverse proxy, WebSocket headers, backups, and hardening.
- Total RAM
- 18.8 MB
- Startup
- 44.8 s
- Port
- 8080
- HTTP
- 200
What ntfy does and what it needs
ntfy is a pub-sub notification server. You publish a message to a topic with a plain HTTP PUT or POST, and every subscriber — phone app, desktop browser, or CLI — gets it instantly. No accounts, no SDKs, no vendor lock-in. The server is a single static Go binary, which makes it a clean fit for a small container.
Under the hood ntfy keeps a message cache on disk and serves a web UI plus a JSON/SSE/WebSocket API. It does not need a database or a cache service. The only state that matters is /var/cache/ntfy (message cache, attachments, user database) and /etc/ntfy (server config).
The upstream project does not publish a minimum memory figure. In practice an idle server with a handful of topics uses very little; memory grows with the number of concurrent WebSocket subscribers and with the size of the message cache you allow. Plan for the subscriber count, not for a fixed number.
Prerequisites, ports, and volume constraints
- Docker Engine 20.10+ and the Compose v2 plugin.
- A domain name pointed at the host if you want HTTPS and mobile push (the Android/iOS apps require a valid TLS certificate for self-hosted servers).
- Port 80 inside the container. The official image listens on
80; we publish it on the host as127.0.0.1:8080so a reverse proxy on the same VPS terminates TLS. - Two persistent paths:
/var/cache/ntfyand/etc/ntfy. Back these up; the cache holds the user database and attachments. - The container runs as a non-root user by default. If you bind-mount host directories,
chownthem to the UID/GID the image uses, or setuser:explicitly in Compose.
If you want to test without a domain, either temporarily change the port mapping to 8080:80 and open the firewall, or keep it on localhost and use an SSH tunnel: ssh -L 8080:127.0.0.1:8080 user@your-vps.
Production Docker Compose setup
Create the project directory and the two config files. The server config lives in /etc/ntfy/server.yml; we generate it from environment variables so secrets stay out of the image.
mkdir -p /opt/ntfy && cd /opt/ntfy
cat <<'EOF' > .env
TZ=UTC
NTFY_BASE_URL=https://ntfy.example.com
NTFY_CACHE_DURATION=12h
NTFY_AUTH_DEFAULT_ACCESS=deny-all
NTFY_ENABLE_SIGNUP=false
NTFY_BEHIND_PROXY=true
EOF
Generate a strong password for the first admin user and store it outside the repo:
openssl rand -hex 32 > admin-password.txt
chmod 600 admin-password.txt
Now the Compose file. It uses the official image, the serve command, and named volumes so the stack boots without host bind mounts:
cat <<'EOF' > compose.yml
services:
ntfy:
image: binwiederhier/ntfy:latest
container_name: ntfy
command: serve
environment:
TZ: ${TZ:-UTC}
NTFY_BASE_URL: ${NTFY_BASE_URL}
NTFY_CACHE_FILE: /var/cache/ntfy/cache.db
NTFY_CACHE_DURATION: ${NTFY_CACHE_DURATION:-12h}
NTFY_AUTH_FILE: /var/cache/ntfy/user.db
NTFY_AUTH_DEFAULT_ACCESS: ${NTFY_AUTH_DEFAULT_ACCESS:-deny-all}
NTFY_ENABLE_SIGNUP: ${NTFY_ENABLE_SIGNUP:-false}
NTFY_BEHIND_PROXY: ${NTFY_BEHIND_PROXY:-true}
NTFY_ATTACHMENT_CACHE_DIR: /var/cache/ntfy/attachments
volumes:
- ntfy-cache:/var/cache/ntfy
- ntfy-etc:/etc/ntfy
ports:
- 127.0.0.1:8080:80
restart: unless-stopped
volumes:
ntfy-cache:
ntfy-etc:
EOF
Start it and confirm the container is healthy by hitting the health endpoint from the host:
docker compose up -d
docker compose logs -f ntfy
curl -s http://127.0.0.1:8080/v1/health
The response should be {"healthy":true}. If it is not, check that NTFY_BASE_URL matches the URL you will actually serve.
Reverse proxy, HTTPS, and first-run hardening
ntfy speaks WebSocket for live subscriptions and uses long-lived HTTP streams for SSE. Your proxy must forward Upgrade and Connection headers and must not buffer responses. It also needs a generous read timeout — clients hold the connection open for minutes.
Caddy example (/etc/caddy/Caddyfile):
ntfy.example.com {
reverse_proxy 127.0.0.1:8080 {
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-For {remote_host}
header_up Host {host}
flush_interval -1
}
}
Nginx equivalent:
server {
listen 443 ssl http2;
server_name ntfy.example.com;
ssl_certificate /etc/letsencrypt/live/ntfy.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ntfy.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_read_timeout 3600s;
client_max_body_size 50m;
}
}
Set NTFY_BEHIND_PROXY=true (already in the Compose file) so ntfy trusts X-Forwarded-* headers. Without it, rate limiting and logging see the proxy IP for every request.
First-run hardening: with NTFY_AUTH_DEFAULT_ACCESS=deny-all and NTFY_ENABLE_SIGNUP=false, anonymous users cannot publish or subscribe. Create the admin account from inside the container:
docker compose exec ntfy ntfy user add --role=admin admin
Paste the password from admin-password.txt when prompted. Then add per-topic permissions for any service that needs to publish, for example:
docker compose exec ntfy ntfy access everyone alerts read-write
Do not leave NTFY_ENABLE_SIGNUP=true on a public instance; anyone who finds the URL can create accounts.
Updating, backups, and common pitfalls
Update the image and recreate the container:
docker compose pull
docker compose up -d
docker compose logs --tail=50 ntfy
Back up the two named volumes. The cache volume holds the user database and attachments; the etc volume holds server.yml if you ever add one.
docker run --rm \
-v ntfy-cache:/data \
-v "$PWD":/backup \
alpine tar czf /backup/ntfy-cache-$(date +%F).tar.gz -C /data .
docker run --rm \
-v ntfy-etc:/data \
-v "$PWD":/backup \
alpine tar czf /backup/ntfy-etc-$(date +%F).tar.gz -C /data .
Restore by extracting the tarball back into the same volume with a throwaway container.
Two pitfalls that bite people:
- Mobile apps reject plain HTTP. The Android and iOS clients require a valid TLS certificate for self-hosted servers. A self-signed cert or an IP address will not work. Use a real domain with Let’s Encrypt, and make sure
NTFY_BASE_URLmatches exactly (scheme included). - Proxy buffering breaks live subscriptions. If the web UI shows messages only after a refresh, your proxy is buffering the response. In Nginx set
proxy_buffering off;and raiseproxy_read_timeout; in Caddy setflush_interval -1. Also confirmUpgradeandConnectionheaders are forwarded, or WebSocket subscriptions will silently fall back to polling.
A third, quieter issue: the message cache grows until NTFY_CACHE_DURATION expires entries. If you attach files, watch disk usage on the ntfy-cache volume and prune old attachments periodically.
Measured in our sandbox run: total memory 18.8 MB (sum of per-container peaks over a 30s idle window after startup) across 1 container; largest container 18.8 MB; published port(s) 8080; HTTP probe returned 200. The run took 44.8s including the image download. Required secret(s) NTFY_BASE_URL were generated for the test run, as the tutorial instructs.
Verification: we ran this docker-compose stack in a disposable Docker environment and recorded the measurements above. They describe that run, not a guarantee for your host.