Run Relay with Docker
Deploy Viaalink Relay and Caddy reverse proxy using Docker Compose with automatic HTTPS.
Container deployment overview
New to Docker and the Relay? Lesson: install Viaalink Relay with Docker takes you through a first install in five steps, without Caddy.
The Viaalink Relay container image (ghcr.io/viaalink/relay, for amd64 and arm64) is public on the GitHub Container Registry: docker pull ghcr.io/viaalink/relay:latest (or a version tag such as 1.39.0). The same image is on Docker Hub as viaalink/viaalink-relay. On a Synology or QNAP NAS, see Run Relay on Synology or QNAP for the NAS-specific steps.
In production, running Viaalink Relay behind Caddy provides automatic Let’s Encrypt certificate issuance, wildcard subdomain management, and HTTP/3 support while Relay manages SSH reverse tunnels and routing.
Prerequisites
- Docker Engine 24.0+ and Docker Compose v2.0+.
- Domain with DNS pointing to your host server (see DNS Configuration):
relay.example.com(A / AAAA)*.relay.example.com(A / AAAA or CNAME)
- Open ports on your firewall or router:
80/tcp,443/tcp,2222/tcp, and optionally3478/udp. This Compose file does not publish the call media port range49152–49167/udpand sets no call relay realm or secret, so calls through firewalls do not work with it.
Deployment files
Create a dedicated directory on your server (for example /opt/viaalink-relay) containing the following configuration files:
mkdir -p /opt/viaalink-relay/data/{keys,ssl,pubkeys,license}
cd /opt/viaalink-relay1. Caddy build with DNS-01 provider plugins (Dockerfile.caddy)
Issuing Let’s Encrypt wildcard certificates (*.relay.example.com) requires ACME DNS-01 validation. Because the stock caddy:2-alpine image does not bundle DNS provider plugins, build a small Caddy image with xcaddy including the five supported DNS providers:
Create Dockerfile.caddy:
FROM caddy:2-builder-alpine AS builder
RUN xcaddy build \
--with github.com/caddy-dns/porkbun \
--with github.com/caddy-dns/cloudflare \
--with github.com/caddy-dns/route53 \
--with github.com/caddy-dns/digitalocean \
--with github.com/caddy-dns/godaddy
FROM caddy:2-alpine
COPY --from=builder /usr/bin/caddy /usr/bin/caddy2. Docker Compose file (docker-compose.yml)
Create docker-compose.yml. A license is activated on one machine, so the container needs the host’s machine ID. The line - /etc/machine-id:/run/host/machine-id:ro mounts it. First check that the host has one:
test -s /etc/machine-id && echo "machine ID found" || echo "no machine ID"If this says no machine ID, do not keep the mount: Docker then creates an empty folder in its place, and license activation fails. On a Linux server, create the ID with sudo systemd-machine-id-setup. On a NAS, use the network card with host networking instead, as described in Run Relay on Synology or QNAP. You can also pass an ID file with --host-id-file.
services:
relay:
image: ghcr.io/viaalink/relay:latest
container_name: viaalink-relay
restart: unless-stopped
ports:
- "2222:2222"
- "3478:3478/udp"
environment:
VIAALINK_RELAY_DOMAIN: relay.example.com
VIAALINK_RELAY_SSH_ADDRESS: ":2222"
VIAALINK_RELAY_HTTP_ADDRESS: ":8080"
VIAALINK_RELAY_PROXY_SSL_TERMINATION: "true"
VIAALINK_RELAY_TRUSTED_PROXIES: "127.0.0.1,172.24.0.0/24"
VIAALINK_RELAY_AUTHENTICATION: "true"
VIAALINK_RELAY_BIND_RANDOM_SUBDOMAINS: "true"
VIAALINK_RELAY_LICENSE_KEY_FILE: "/app/deploy/license/license.jwt"
VIAALINK_RELAY_LOG_JSON: "true"
VIAALINK_RELAY_LOG_TO_STDOUT: "true"
volumes:
- /etc/machine-id:/run/host/machine-id:ro
- ./data/keys:/app/deploy/keys
- ./data/pubkeys:/app/deploy/pubkeys
- ./data/ssl:/app/deploy/ssl
- ./data/license:/app/deploy/license
- ./data/config.yml:/app/config.yml
networks:
- relay-net
caddy:
build:
context: .
dockerfile: Dockerfile.caddy
container_name: viaalink-caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
environment:
CLOUDFLARE_API_TOKEN: your-cloudflare-api-token
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
networks:
- relay-net
depends_on:
- relay
networks:
relay-net:
driver: bridge
ipam:
config:
- subnet: 172.24.0.0/24
volumes:
caddy-data:
caddy-config:The network relay-net uses the fixed range 172.24.0.0/24, so the Relay knows Caddy’s address. If another Docker network on the host already uses that range, Compose cannot create the network. List the ranges in use with docker network ls and docker network inspect <name>. To use another free private range, change it in three places: subnet: in this file, VIAALINK_RELAY_TRUSTED_PROXIES in this file, and trusted-proxies: in data/config.yml.
3. Caddy reverse proxy configuration (Caddyfile)
Create Caddyfile in the same directory with the tls DNS-01 challenge block for your DNS provider (Cloudflare shown below):
{
email admin@example.com
servers {
protocols h1 h2 h3
}
}
# Primary host and wildcard subdomains (DNS-01 required for *.relay.example.com)
relay.example.com, *.relay.example.com {
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}
reverse_proxy relay:8080 {
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-Host {host}
header_up X-Forwarded-Port {port}
}
encode gzip
}4. Initial Relay configuration (data/config.yml)
Create data/config.yml:
domain: relay.example.com
ssh-address: :2222
http-address: :8080
proxy-ssl-termination: true
trusted-proxies: 127.0.0.1,172.24.0.0/24
authentication: true
bind-random-subdomains: true
log-json: true
log-to-stdout: true
private-keys-directory: /app/deploy/keys
authentication-keys-directory: /app/deploy/pubkeys
https-certificate-directory: /app/deploy/ssl
license-key-file: /app/deploy/license/license.jwtStarting the stack
Build and start both containers in detached mode:
docker compose up -d --buildCheck the status of running containers:
docker compose psView the Relay server logs to verify startup and find the setup code:
docker compose logs -f relayThe setup code is in the line that starts with Setup dashboard token:. The Relay makes a new code each time it starts, so use the newest line. The code is also in data/license/setup-token.txt, which only root can read.
Open the setup dashboard at https://relay.example.com/_relay/dashboard?x-authorization=<setup-code>. This works once DNS, port forwarding, Caddy and its certificate are in place.
To sign in earlier from your own network, publish the Relay’s HTTP port: add - "8080:8080" under ports: of the relay service, run docker compose up -d, and open http://<server-ip>:8080/_relay/dashboard?x-authorization=<setup-code>. Do this only on a machine in your own network, never on a server with a public IP address, and do not forward port 8080 on your router. Remove the line again after setup.
Settings that need a restart make the Relay stop itself after a short delay; Docker’s restart: unless-stopped policy brings it back up. The dashboard shows a restart bar with options: Restart now, Tonight at …, or Undo. Restart now stops the Relay, and Compose starts it again. This is in Relay v1.36.0 and later, and in the ASUSTOR package 0.62.7 and later.
Settings in ./data/config.yml are overridden by the environment variables in this Compose file (VIAALINK_RELAY_DOMAIN, VIAALINK_RELAY_SSH_ADDRESS, and so on). A domain or port changed in the dashboard is written to config.yml but ignored after the restart. Keep domain and ports in config.yml only, and remove those variables from the Compose file if you want the dashboard to control them.
Persistent volumes and storage
All critical persistent state is preserved in the ./data directory on the host:
| Host Directory | Container Path | Purpose |
|---|---|---|
/etc/machine-id | /run/host/machine-id | Host machine ID required for bound license activation |
./data/keys/ | /app/deploy/keys | Server SSH private host keys (generated on first boot) |
./data/pubkeys/ | /app/deploy/pubkeys | Authorized client SSH public keys |
./data/ssl/ | /app/deploy/ssl | Custom SSL certificates and keys |
./data/license/ | /app/deploy/license | License file (license.jwt) and setup-token.txt |
./data/config.yml | /app/config.yml | Writable Relay configuration file (updated by /_relay/dashboard) |
caddy-data volume | /data | Caddy Let’s Encrypt certificates and account keys |
DNS-01 provider credentials
When configuring the tls { dns ... } directive in Caddyfile (or when Relay drives a bundled Caddy binary with --caddy-https-enabled=true), use the environment variables for your provider:
| Provider | Caddyfile dns directive | Environment Variables |
|---|---|---|
| Porkbun | dns porkbun { api_key {env.PORKBUN_API_KEY} api_secret_key {env.PORKBUN_API_SECRET_KEY} } | PORKBUN_API_KEY, PORKBUN_API_SECRET_KEY |
| Cloudflare | dns cloudflare {env.CLOUDFLARE_API_TOKEN} | CLOUDFLARE_API_TOKEN |
| AWS Route53 | dns route53 { access_key_id {env.AWS_ACCESS_KEY_ID} secret_access_key {env.AWS_SECRET_ACCESS_KEY} region {env.AWS_REGION} } | AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION |
| DigitalOcean | dns digitalocean {env.DIGITALOCEAN_API_TOKEN} | DIGITALOCEAN_API_TOKEN |
| GoDaddy | dns godaddy {env.GODADDY_API_TOKEN} | GODADDY_API_TOKEN |
Upgrading
To update Viaalink Relay and Caddy, pull the updated images and restart the containers:
docker compose pull && docker compose up -dup -d alone does not fetch a newer image: the relay service uses the published image, so it needs pull first. Only the Caddy service is built locally.
Existing client connections will automatically reconnect when the new container starts.
Verifying health
Operational health is verified when:
- Port
2222responds to SSH connections:bashssh -p 2222 relay.example.com - Your browser reaches
https://relay.example.com/_relay/dashboardor a published test application over HTTPS.
Next steps
- Manage connecting devices and public keys in Access Control and Security.
- Activate a paid plan in Relay Licensing.
- Connect developer devices with Install the Viaalink CLI.