惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
罗磊的独立博客
小众软件
小众软件
I
InfoQ
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
MyScale Blog
MyScale Blog
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
博客园 - 司徒正美
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
N
Netflix TechBlog - Medium

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Self-hosting NATS on Dokploy in under 10 minutes
Huy Pham · 2026-05-12 · via DEV Community
Cover image for Self-hosting NATS on Dokploy in under 10 minutes

Huy Pham

Huy Pham

Posted on • Edited on

You picked Dokploy because you wanted Heroku-flavored ergonomics on your own VPS. Then you needed a message bus — pub/sub, JetStream persistence, maybe a WebSocket endpoint for the browser — and suddenly you're back in the YAML mines: writing a nats.conf, figuring out where the token lives, working out why Traefik won't terminate TLS in front of a raw TCP port, and wondering whether /varz is safe to expose to the internet (spoiler: it isn't).

I hit every one of those and packaged the fix as a single Dokploy Compose service: quochuydev/dokploy-nats. This post is the walkthrough I wish I'd had.

What you get

One docker-compose.yml that gives you:

  • NATS core on 4222 for in-cluster apps
  • JetStream with file-backed persistence (durable streams, KV, object store)
  • WebSocket on 8080, ready to put behind Traefik as wss://
  • HTTP monitoring on 8222/healthz, /varz, /connz, /jsz
  • Token auth wired through env vars, no plaintext in the repo

It's deliberately boring. No operator JWT, no clustering, no leaf nodes — just the smallest thing that's actually useful for a side project or a small team.

Step 1 — Create the Compose service

In Dokploy: Create Service → Compose, point it at the repo (or your fork), branch main, compose path docker-compose.yml. That's the entire "deploy" step.

Step 2 — Set a real token

The one thing you must not skip. In the Environment tab paste .env.example and replace the token:

openssl rand -hex 32

Drop the output into NATS_AUTH_TOKEN. The container reads nats.conf which references $NATS_AUTH_TOKEN — no rebuild needed, just redeploy.

Step 3 — Expose the two HTTP-shaped ports

Traefik routes HTTP(S), not raw TCP, so the two ports you can publish over your domain are the monitoring endpoint and the WebSocket endpoint:

Host Service Container Port
nats-monitor.<your-domain> nats 8222
nats-ws.<your-domain> nats 8080

Add both in the service's Domains tab. Dokploy will provision certs.

Step 4 — Lock down /varz

This is the step everyone forgets. The monitoring endpoint cheerfully tells the world your subjects, connected clients, JetStream sizes, and server version. You want basic auth in front of it.

Generate a hashed credential:

htpasswd -nb admin 'a-real-password'

Open Dokploy → Settings → Traefik and add to middlewares.yml:

http:
  middlewares:
    nats-monitor-auth:
      basicAuth:
        users:
          - "admin:$apr1$G3T3XOqn$6JGifVcvveyWFg7gYWZjH0"

Then attach nats-monitor-auth@file to the nats-monitor row in Domains. Done — /varz now prompts for credentials.

Step 5 — Talk to it

Install the NATS CLI and save a context pointing at your WebSocket URL:

nats context save dokploy \
  --server wss://nats-ws.<your-domain> \
  --token "$NATS_AUTH_TOKEN" \
  --select

nats sub demo &
nats pub demo "hello from dokploy"

For JetStream:

nats stream add events --subjects "events.*" --storage file --defaults
nats pub events.user.signup '{"id":"u1"}'
nats stream view events

If you want to see this from an actual app, examples/node has a Fastify UI plus a worker showing request/reply, live WebSocket events, and prefix-scoped subscriptions.

The 4222 question

Traefik can't proxy the native protocol. If you need apps outside the Dokploy host to use port 4222 directly, you have two options:

  1. Add ports: ["4222:4222"] to the nats service and open the firewall (and seriously consider TLS — see "Extending" in the README).
  2. Use the WebSocket endpoint from any client that supports it — every official NATS client does.

For most setups, option 2 is the right answer. Browser clients get the same endpoint as your services, and you only have one thing to secure.

When to outgrow this setup

This repo is intentionally a starting point. The moment you need any of:

  • TLS/mTLS between services — add a tls { ... } block to nats.conf
  • Clustering or leaf nodescluster { ... } / leafnodes { ... } blocks
  • Per-account isolation or JWT auth — swap the authorization block for accounts + operator JWT
  • KV or Object store — already enabled by JetStream, just nats kv add after deploy

…edit nats.conf or docker-compose.yml, push, redeploy. Nothing magic.

Wrap-up

Five steps, one token, two domains, one Traefik middleware. You now have a durable, browser-reachable, password-protected NATS server running next to your other Dokploy apps for the cost of the disk space JetStream uses.

If you spin it up, I'd love to hear what broke. Issues and PRs welcome: github.com/quochuydev/dokploy-nats.