# ๐ง
Tor Guard Relay
[](https://github.com/r3bo0tbx1/tor-guard-relay/actions/workflows/release.yml)
[](https://github.com/r3bo0tbx1/tor-guard-relay/releases/latest)

[](https://hub.docker.com/r/r3bo0tbx1/onion-relay)
[](LICENSE.txt)

**A hardened, production-ready Tor relay with built-in diagnostics and monitoring**
[Quick Start](#-quick-start) โข [Features](#-key-features) โข [Documentation](#-documentation) โข [FAQ](docs/FAQ.md) โข [Architecture](docs/ARCHITECTURE.md) โข [Tools](#-diagnostic-tools) โข [Contributing](#-contributing)
---
## ๐ What is This?
**Tor Guard Relay** is a production-ready, self-healing Tor relay container designed for privacy advocates who want to contribute to the Tor network securely and efficiently.
> ๐ **Multi-Mode:** guard, exit, and bridge with obfs4 transport. Configure via `TOR_RELAY_MODE`.
### Why Choose This Project?
- ๐ก๏ธ **Security-First** - Hardened Alpine Linux, non-root operation, and minimized port exposure
- ๐ชถ **Very light** - Ultra-minimal 16.8 MB image
- ๐ฏ **Simple** - One command to deploy, minimal configuration needed
- ๐ **Observable** - 6 busybox-only diagnostic tools with JSON health API
- ๐ **Multi-Mode** - Supports guard, exit, and bridge (obfs4) relays
- ๐ **Automated** - Weekly security rebuilds, CI/CD ready
- ๐ **Documented** - Comprehensive guides for deployment, monitoring, backup, and more
- ๐๏ธ **Multi-Arch** - Native support for AMD64 and ARM64 (Raspberry Pi, AWS Graviton, etc.)
---
## ๐ Security Model
### Port Exposure Policy
- **9001** ORPort, public
- **9030** DirPort, **Disabled (0)** by default
- **9002** obfs4 for bridge mode
### Environment Variables
- `TOR_ORPORT` default 9001
- `TOR_DIRPORT` default 0 (Disabled)
- `TOR_OBFS4_PORT` default 9002
Diagnostics are run only through `docker exec`, with no exposed monitoring ports.
Minimal surface area, roughly 16.8 MB.
---
## โก Quick Start
### System Requirements
| Component | Minimum | Recommended |
|----------|----------|-------------|
| CPU | 1 core | 2+ cores |
| RAM | 512 MB | 1 GB+ |
| Disk | 10 GB | 20 GB+ SSD |
| Bandwidth | 10 Mbps | 100+ Mbps |
| Uptime | 95 percent | 99 percent |
| Docker | 20.10+ | Latest |
**Supported Architectures:** AMD64, ARM64
### Network Security Notes
โ ๏ธ **Port Exposure:**
- **Guard/Middle/Exit:** Port 9001 (ORPort) should be publicly accessible
- **Bridge:** Ports 9001 (ORPort) and 9002 (obfs4) should be publicly accessible
- **No monitoring ports** - all diagnostics via `docker exec` commands only
- Use `--network host` for best IPv6 support (Tor recommended practice)
### Interactive Quick Start (Recommended for Beginners)
**๐ Try our interactive setup script:**
```bash
# Download and run the quick-start script
curl -fsSL https://raw.githubusercontent.com/r3bo0tbx1/tor-guard-relay/main/scripts/quick-start.sh -o quick-start.sh
chmod +x quick-start.sh
sh ./quick-start.sh
```
The script will:
- โ
Guide you through relay type selection (guard, exit, bridge)
- โ
Collect required information with validation
- โ
Generate deployment commands or docker-compose.yml
- โ
Provide next steps and monitoring guidance
### Manual Deployment
**Step 1:** Create your relay configuration (or use our [example](examples/relay-guard.conf)):
```bash
mkdir -p ~/tor-relay && cd ~/tor-relay
curl -o relay.conf https://raw.githubusercontent.com/r3bo0tbx1/tor-guard-relay/refs/heads/main/examples/relay-guard.conf
nano relay.conf
```
**Step 2:** Run (Docker Hub)
```bash
docker run -d \
--name tor-relay \
--restart unless-stopped \
--network host \
--security-opt no-new-privileges:true \
-v $(pwd)/relay.conf:/etc/tor/torrc:ro \
-v tor-guard-data:/var/lib/tor \
-v tor-guard-logs:/var/log/tor \
r3bo0tbx1/onion-relay:latest
```
**Step 3:** Verify it's running:
```bash
# Check status
docker exec tor-relay status
# View fingerprint
docker exec tor-relay fingerprint
# Stream logs
docker logs -f tor-relay
```
**That's it!** Your relay will bootstrap in 10-30 minutes and appear on [Tor Metrics](https://metrics.torproject.org/rs.html) within 1-2 hours.
> ๐ **Need more?** See our comprehensive [Deployment Guide](docs/DEPLOYMENT.md) for Docker Compose, Cosmos Cloud, Portainer, and advanced setups.
---
## ๐ฏ Choosing a Variant
We offer **two build variants** to match your risk tolerance and requirements:
### Stable Variant (Recommended)
**Base:** Alpine 3.23.3 | **Recommended for:** Production relays
- โ
Battle-tested Alpine stable release
- โ
Weekly automated rebuilds with latest security patches
- โ
Proven stability for long-running relays
- โ
Available on both **Docker Hub** and **GHCR**
```bash
# Pull from Docker Hub (easiest)
docker pull r3bo0tbx1/onion-relay:latest
docker pull r3bo0tbx1/onion-relay:1.1.7
# Pull from GHCR
docker pull ghcr.io/r3bo0tbx1/onion-relay:latest
docker pull ghcr.io/r3bo0tbx1/onion-relay:1.1.7
```
### Edge Variant (Testing Only)
**Base:** Alpine edge | **Recommended for:** Testing, security research
- โก Bleeding-edge Alpine packages (faster security updates)
- โก Latest Tor and obfs4 versions as soon as available
- โก **More frequent rebuilds** - Every 3 days + weekly (~2-3x faster updates than stable)
- โ ๏ธ **NOT recommended for production** - less stable, potential breaking changes
- ๐ฆ Available on both Docker Hub and GHCR
```bash
# Pull from Docker Hub
docker pull r3bo0tbx1/onion-relay:edge
# Pull from GHCR
docker pull ghcr.io/r3bo0tbx1/onion-relay:edge
docker pull ghcr.io/r3bo0tbx1/onion-relay:1.1.7-edge
```
**When to use edge:**
- ๐ฌ Testing new Tor features before stable release
- ๐ก๏ธ Security research requiring latest packages
- ๐งช Non-production test environments
- ๐ Early adopters willing to accept potential breakage
**Stability comparison:**
| Feature | Stable | Edge |
|---------|--------|------|
| Production ready | โ
Yes | โ No |
| Breaking changes | โ Rare | โ ๏ธ Possible |
| Security updates | Weekly | Every 3 days |
| Package versions | 3.23.3 | Bleeding edge |
| Docker Hub | โ
Yes | โ
Yes |
| GHCR | โ
Yes | โ
Yes |
> ๐ก **Our recommendation:** Use **stable** for production relays, **edge** only for testing or when you specifically need the latest package versions.
---
## ๐๏ธ Deployment Methods
Choose the method that fits your workflow.
| Method | Best For | Guide |
|--------|----------|--------|
| ๐ณ Docker CLI | Quick testing | [Guide](docs/DEPLOYMENT.md#method-1-docker-cli) |
| ๐ฆ Docker Compose | Production | [Guide](docs/DEPLOYMENT.md#method-2-docker-compose) |
| โ๏ธ Cosmos Cloud | UI based deployment | [Guide](docs/DEPLOYMENT.md#method-3-cosmos-cloud) |
| ๐๏ธ Portainer | Web UI | [Guide](docs/DEPLOYMENT.md#method-4-portainer) |
**New to Docker?** Try [Cosmos Cloud](https://cosmos-cloud.io/) by [azukaar](https://github.com/azukaar) - a gorgeous, self-hosted Docker management platform.
### Multi-Relay Setup
Running multiple relays? We have templates for that:
- **Docker Compose:** [docker-compose-multi-relay.yml](templates/docker-compose-multi-relay.yml) - 3 relays setup
- **Cosmos Cloud:** [cosmos-compose-multi-relay.json](templates/cosmos-compose-multi-relay.json) - Multi-relay stack
See [Deployment Guide](docs/DEPLOYMENT.md) for complete instructions.
---
## ๐ง Diagnostic Tools
Six busybox-only diagnostic tools are included.
| Tool | Purpose | Usage |
|------|---------|--------|
| status | Full health report | `docker exec tor-relay status` |
| health | JSON health | `docker exec tor-relay health` |
| fingerprint | Show fingerprint | `docker exec tor-relay fingerprint` |
| bridge-line | obfs4 line | `docker exec tor-relay bridge-line` |
| gen-auth | Credentials for Nyx | `docker exec tor-relay gen-auth` |
| gen-family | Happy Family key gen | `docker exec tor-relay gen-family MyRelays` |
```bash
# Full health report with emojis
docker exec tor-relay status
# JSON output for automation/monitoring
docker exec tor-relay health
```
Example JSON:
```json
{
"status": "up",
"pid": 1,
"uptime": "01:00:00",
"bootstrap": 100,
"reachable": "true",
"errors": 0,
"nickname": "MyRelay",
"fingerprint": "1234567890ABCDEF"
}
```
> ๐ **Complete reference:** See [Tools Documentation](docs/TOOLS.md) for all 6 tools with examples, JSON schema, and integration guides.
---
## ๐ Monitoring and Observability