uncloud
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUncloud Cluster Management
Uncloud集群管理
Reference for the CLI — a decentralised self-hosting platform using Docker containers, WireGuard mesh networking, and Caddy reverse proxy.
ucucWhen to Activate
适用场景
Use this skill when working with Uncloud clusters, especially when:
- Bootstrapping or joining machines with
uc machine - Deploying services from Compose files with
uc deploy - Publishing HTTP, HTTPS, TCP, or UDP ports through Uncloud
- Configuring Caddy ingress with ,
x-caddy, orx-ports--caddyfile - Routing external LAN devices through the cluster proxy
- Inspecting logs, service state, volumes, DNS, or machine placement
在处理Uncloud集群时使用此技能,尤其是在以下场景:
- 使用引导或加入机器
uc machine - 使用从Compose文件部署服务
uc deploy - 通过Uncloud发布HTTP、HTTPS、TCP或UDP端口
- 使用、
x-caddy或x-ports配置Caddy入口--caddyfile - 通过集群代理路由外部LAN设备
- 查看日志、服务状态、卷、DNS或机器部署位置
How It Works
工作原理
Uncloud runs Docker services across peer machines connected by a WireGuard mesh. Each machine is an equal cluster member; services communicate on the overlay network and Caddy runs globally to terminate public HTTP/HTTPS traffic. Compose files can use Uncloud extensions for ingress, placement, and generated Caddy configuration, while the CLI handles image distribution, scheduling, scaling, logs, and cluster state.
ucUncloud在通过WireGuard网格连接的对等机器上运行Docker服务。每台机器都是平等的集群成员;服务通过覆盖网络通信,Caddy全局运行以终止公共HTTP/HTTPS流量。Compose文件可使用Uncloud扩展进行入口配置、部署位置设置和生成Caddy配置,而 CLI负责镜像分发、调度、扩容、日志和集群状态管理。
ucExamples
示例
bash
uc machine init user@host --name machine-1
uc service run --name web -p app.example.com:8080/https nginx:latest
uc deploybash
uc machine init user@host --name machine-1
uc service run --name web -p app.example.com:8080/https nginx:latest
uc deployCore Concepts
核心概念
- No central control plane — all machines are equal peers connected by WireGuard
- Caddy runs as a global service on every machine; auto-obtains TLS from Let's Encrypt
- Overlay network — services communicate via by default; DNS provided inside the mesh
10.210.0.0/16 - Caddyfile is autogenerated — never edit it directly; use /
x-caddyinstead--caddyfile
- 无中央控制平面 —— 所有机器都是通过WireGuard连接的平等节点
- Caddy作为全局服务在每台机器上运行;自动从Let's Encrypt获取TLS证书
- 覆盖网络 —— 服务默认通过通信;网格内提供DNS服务
10.210.0.0/16 - Caddyfile自动生成 —— 切勿直接编辑;请使用/
x-caddy替代--caddyfile
CLI Quick Reference
CLI快速参考
Machines
机器管理
| Command | Purpose |
|---|---|
| Bootstrap first machine / new cluster |
| Join machine to existing cluster |
| List machines |
| Update public IP for ingress |
| Remove machine |
Key flags: , , , ,
init--name--network 10.210.0.0/16--no-caddy--no-dns--public-ip auto\|IP\|none| 命令 | 用途 |
|---|---|
| 引导首台机器/创建新集群 |
| 将机器加入现有集群 |
| 列出所有机器 |
| 更新入口的公网IP |
| 删除机器 |
init--name--network 10.210.0.0/16--no-caddy--no-dns--public-ip auto\|IP\|noneServices
服务管理
| Command | Purpose |
|---|---|
| List services |
| Run a single container service |
| Deploy from |
| Deploy already-pushed images without rebuilding |
| Force service recreation |
| Set replica count |
| View logs |
| Shell into container |
| Detailed info |
| Remove service (keeps named volumes) |
| All containers across cluster |
| 命令 | 用途 |
|---|---|
| 列出所有服务 |
| 运行单个容器服务 |
| 从 |
| 部署已推送的镜像,无需重新构建 |
| 强制重新创建服务 |
| 设置副本数量 |
| 查看日志 |
| 进入容器Shell |
| 查看详细信息 |
| 删除服务(保留命名卷) |
| 查看集群中所有容器 |
Images
镜像管理
bash
uc image push myapp:latest # Push local image to all machines
uc image push myapp:latest -m machine1,machine2 # Push to specific machines
uc images # List images in clusterbash
uc image push myapp:latest # 将本地镜像推送到所有机器
uc image push myapp:latest -m machine1,machine2 # 将镜像推送到指定机器
uc images # 列出集群中的镜像Volumes
卷管理
bash
uc volume ls # All volumes
uc volume ls -m machine1 # On specific machine
uc volume create NAME -m MACHINE
uc volume rm NAMEbash
uc volume ls # 查看所有卷
uc volume ls -m machine1 # 查看指定机器上的卷
uc volume create NAME -m MACHINE
uc volume rm NAMECaddy
Caddy管理
bash
uc caddy config # Show current generated Caddyfile (read-only)
uc caddy deploy # Deploy/upgrade Caddy across clusterbash
uc caddy config # 查看当前生成的Caddyfile(只读)
uc caddy deploy # 在集群中部署/升级CaddyDNS & Context
DNS与上下文
bash
uc dns show # Show reserved *.uncld.dev domain
uc dns reserve # Reserve a new domain
uc ctx ls # List cluster contexts
uc ctx use prod # Switch contextbash
uc dns show # 查看保留的*.uncld.dev域名
uc dns reserve # 保留新域名
uc ctx ls # 列出集群上下文
uc ctx use prod # 切换上下文Port Publishing
端口发布
HTTP/HTTPS (via Caddy reverse proxy)
HTTP/HTTPS(通过Caddy反向代理)
-p [hostname:]container_port[/protocol]| Example | Meaning |
|---|---|
| HTTPS with auto |
| HTTPS with custom hostname |
| HTTP only, no TLS |
-p [hostname:]container_port[/protocol]| 示例 | 说明 |
|---|---|
| HTTPS协议,自动使用 |
| HTTPS协议,使用自定义主机名 |
| 仅HTTP协议,无TLS加密 |
TCP/UDP (host-bound, bypasses Caddy)
TCP/UDP(绑定主机,绕过Caddy)
-p [host_ip:]host_port:container_port[/protocol]@host| Example | Meaning |
|---|---|
| TCP 5432 on all interfaces |
| TCP 5432 loopback only |
| UDP |
-p [host_ip:]host_port:container_port[/protocol]@host| 示例 | 说明 |
|---|---|
| 在所有接口上开放TCP 5432端口 |
| 仅在回环接口开放TCP 5432端口 |
| 开放UDP端口 |
Compose File Extensions
Compose文件扩展
Uncloud adds these extensions on top of Docker Compose:
Uncloud在Docker Compose基础上添加了以下扩展:
x-ports
— publish ports with domains
x-portsx-ports
—— 带域名的端口发布
x-portsyaml
services:
app:
image: app:latest
x-ports:
- example.com:8000/https
- www.example.com:8000/https
- api.example.com:9000/httpsyaml
services:
app:
image: app:latest
x-ports:
- example.com:8000/https
- www.example.com:8000/https
- api.example.com:9000/httpsx-caddy
— custom Caddy config for service
x-caddyx-caddy
—— 服务的自定义Caddy配置
x-caddyyaml
services:
app:
image: app:latest
x-caddy: |
example.com {
redir https://www.example.com{uri} permanent
}
www.example.com {
reverse_proxy {{upstreams 8000}} {
import common_proxy
}
basic_auth /admin/* {
admin $2a$14$...
}
}Template functions available inside :
x-caddy- — healthy container IPs
{{upstreams [service] [port]}} - — service name
{{.Name}} - — map of all services → IPs
{{.Upstreams}}
yaml
services:
app:
image: app:latest
x-caddy: |
example.com {
redir https://www.example.com{uri} permanent
}
www.example.com {
reverse_proxy {{upstreams 8000}} {
import common_proxy
}
basic_auth /admin/* {
admin $2a$14$...
}
}x-caddy- —— 健康容器的IP地址
{{upstreams [service] [port]}} - —— 服务名称
{{.Name}} - —— 所有服务→IP的映射
{{.Upstreams}}
x-machines
— placement constraints
x-machinesx-machines
—— 部署位置约束
x-machinesyaml
services:
db:
image: postgres:18
x-machines: db-machine # Single machine name
app:
image: app:latest
x-machines:
- machine-1
- machine-2yaml
services:
db:
image: postgres:18
x-machines: db-machine # 指定单个机器名称
app:
image: app:latest
x-machines:
- machine-1
- machine-2Full multi-service example
完整多服务示例
yaml
services:
api:
build: ./api
x-ports:
- api.example.com:3000/https
environment:
DATABASE_URL: postgres://db:5432/mydb
web:
build: ./web
x-ports:
- example.com:8000/https
- www.example.com:8000/https
environment:
API_URL: http://api:3000
db:
image: postgres:18
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- db-data:/var/lib/postgresql/data
x-machines: db-machine
volumes:
db-data:yaml
services:
api:
build: ./api
x-ports:
- api.example.com:3000/https
environment:
DATABASE_URL: postgres://db:5432/mydb
web:
build: ./web
x-ports:
- example.com:8000/https
- www.example.com:8000/https
environment:
API_URL: http://api:3000
db:
image: postgres:18
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- db-data:/var/lib/postgresql/data
x-machines: db-machine
volumes:
db-data:Routing to External (Non-Cluster) Devices
路由到外部(非集群)设备
To expose an external device (e.g. BMC, NAS, router UI) via Caddy without running a real container:
1. Create a Caddyfile snippet (e.g. ):
~/device.caddyfilecaddyfile
https://device.example.com {
reverse_proxy https://192.168.1.x {
transport http {
tls_insecure_skip_verify # needed for self-signed BMC certs
}
}
log
}For plaintext upstream:
reverse_proxy http://192.168.1.x:port2. Register as a named service with no-op container:
bash
uc service run \
--name device-bmc \
--caddyfile ~/device.caddyfile \
registry.k8s.io/pause:3.9pause3. Verify:
bash
uc caddy config # device.example.com block should appearcannot be combined with non---caddyfilepublished ports.@host
DNS tip: A wildcard record () means any new subdomain works immediately — no DNS change needed per service.
*.yourdomain.com → cluster-public-ip要通过Caddy暴露外部设备(如BMC、NAS、路由器UI)而无需运行真实容器:
1. 创建Caddyfile片段(例如):
~/device.caddyfilecaddyfile
https://device.example.com {
reverse_proxy https://192.168.1.x {
transport http {
tls_insecure_skip_verify # 自签名BMC证书需要此配置
}
}
log
}对于明文上游服务:
reverse_proxy http://192.168.1.x:port2. 注册为带无操作容器的命名服务:
bash
uc service run \
--name device-bmc \
--caddyfile ~/device.caddyfile \
registry.k8s.io/pause:3.9pause3. 验证:
bash
uc caddy config # 应显示device.example.com配置块不能与非--caddyfile类型的发布端口结合使用。@host
DNS提示: 通配符记录()意味着任何新子域名可立即生效——无需为每个服务修改DNS。
*.yourdomain.com → cluster-public-ipService DNS (Internal)
服务DNS(内部)
Services inside the cluster resolve each other by name:
| DNS name | Resolves to |
|---|---|
| Any healthy container |
| Same |
| Round-robin |
| Machine-local first |
集群内的服务可通过名称相互解析:
| DNS名称 | 解析目标 |
|---|---|
| 任意健康容器 |
| 同上 |
| 轮询解析 |
| 优先解析本地机器上的容器 |
Scaling & Global Services
扩容与全局服务
bash
uc scale web 5 # 5 replicas (spread across machines)
uc scale web 1 # Scale downyaml
services:
caddy:
deploy:
mode: global # One container on every machinebash
uc scale web 5 # 5个副本(分布在多台机器上)
uc scale web 1 # 缩容yaml
services:
caddy:
deploy:
mode: global # 在每台机器上运行一个容器Image Tag Templates (in compose.yaml)
镜像标签模板(在compose.yaml中)
yaml
image: myapp:{{gitdate "20060102"}}.{{gitsha 7}}
image: myapp:{{gitsha 7}}.${GITHUB_RUN_ID:-local}| Function | Output |
|---|---|
| First N chars of commit SHA |
| Git commit date in Go format |
| Current date |
yaml
image: myapp:{{gitdate "20060102"}}.{{gitsha 7}}
image: myapp:{{gitsha 7}}.${GITHUB_RUN_ID:-local}| 函数 | 输出 |
|---|---|
| 提交SHA的前N个字符 |
| Go格式的Git提交日期 |
| 当前日期 |
Common Workflows
常见工作流
Deploy from source:
bash
uc deploy # Build + push + deploy
uc build --push && uc deploy --no-build # Separate stepsInspect a service:
bash
uc inspect web
uc logs -f web
uc logs --since 1h web
uc exec web # Opens shell
uc exec web /bin/sh -c "env" # Run specific commandZero-downtime deploys happen automatically; Uncloud waits for health checks before terminating old containers.
Force recreate:
bash
uc deploy --recreate从源码部署:
bash
uc deploy # 构建 + 推送 + 部署
uc build --push && uc deploy --no-build # 分步执行检查服务:
bash
uc inspect web
uc logs -f web
uc logs --since 1h web
uc exec web # 打开Shell
uc exec web /bin/sh -c "env" # 运行指定命令零停机部署自动完成;Uncloud在终止旧容器前会等待健康检查通过。
强制重新创建:
bash
uc deploy --recreateCommon Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Editing the Caddyfile directly | Use |
| Proxying an HTTPS upstream with self-signed cert | Add |
| Caddy admin socket unreachable — check |
| Service can't reach external LAN IP from container | Verify Caddy container's host can route to target network |
Volumes lost after | Named volumes persist; only anonymous volumes are auto-removed |
| 错误 | 修复方案 |
|---|---|
| 直接编辑Caddyfile | 在compose中使用 |
| 代理带自签名证书的HTTPS上游服务 | 添加 |
| Caddy管理套接字不可达——检查 |
| 容器内的服务无法访问外部LAN IP | 验证Caddy容器所在主机可路由到目标网络 |
| 命名卷会保留;仅匿名卷会被自动删除 |