Skip to content

Docker Compose

The repo has three Compose files at its root:

FileServicesFor
docker-compose.single.ymlpostgres (16), virviOne server. No Redis.
docker-compose.scalable.ymlpostgres (16), redis (7), virviSeveral Virvi containers sharing Redis.
docker-compose.dev.ymlpostgres (16), redis (7), minioLocal development. Runs no Virvi server.

The virvi service builds the root Dockerfile (Node 20, Alpine). The image holds the API server, the dashboard, these docs and FFmpeg.

Single mode

Run every command from the repo root.

1. Get the code

Terminal window
git clone https://github.com/virvi-xr/virvi.git
cd virvi

2. Write .env

Docker Compose reads .env in the repo root to fill in the Compose file. Single mode uses these four:

Terminal window
cat > .env <<EOF
JWT_SECRET=$(openssl rand -hex 32)
POSTGRES_PASSWORD=$(openssl rand -hex 16)
PUBLIC_URL=http://localhost:3010
PORT=3010
EOF
VariableNeededUsed for
JWT_SECRETYes. Compose stops with Set JWT_SECRET in .env without itSigning sign-in tokens
POSTGRES_PASSWORDNo (default vlm_prod). Set your ownThe vlm database user’s password
PUBLIC_URLNo (default http://localhost:3010)The address people use to reach the server
PORTNo (default 3010)The port on the host. The container always listens on 3010

Set POSTGRES_PASSWORD before the first start. Postgres keeps the password it was created with; changing it later breaks the connection.

3. Start

Terminal window
docker compose -f docker-compose.single.yml up -d --build

The first build takes several minutes. On start, the container syncs the database schema, then starts the server.

4. Check it

Terminal window
curl -s http://localhost:3010/api/health

A healthy server answers 200 with "status":"ok" and "postgres":"ok". See Updating and Troubleshooting if not.

5. Create the admin account

Open http://localhost:3010 and sign up. The first account on a new install becomes its instance admin. Do this straight away on a public server: whoever signs up first gets admin.

What the single file sets up

  • postgres: database vlm, user vlm, data in the pgdata volume. Port 5432 is published on 127.0.0.1 only, for tools on the same machine.
  • virvi: VIRVI_MODE=single, STORAGE_PROVIDER=local, uploads in the uploads volume (/app/uploads) and private import files in the private volume (/app/private).

Your own domain

Two things change when people reach the server at a real address, such as https://virvi.example.com.

1. The dashboard’s addresses are built into the image. The Compose files build it with PUBLIC_URL from .env as its API address. Add its WebSocket address to .env too, then rebuild:

.env
PUBLIC_URL=https://virvi.example.com
NEXT_PUBLIC_WSS_URL=wss://virvi.example.com
Terminal window
docker compose -f docker-compose.single.yml up -d --build

Rebuild whenever you change either one.

2. The server needs its public address and the proxy count. Set PUBLIC_URL=https://virvi.example.com in .env, and set TRUST_PROXY_HOPS for your proxy (see below).

Put a reverse proxy (Caddy, nginx, Traefik) in front for HTTPS. It must pass WebSocket upgrades: real-time sync runs on the same port as the API. With Caddy, reverse_proxy localhost:3010 does both.

Adding more variables

Every line of .env reaches the server (the Compose files load it with env_file). To set more (SMTP, OAuth, TRUST_PROXY_HOPS and so on), add them to .env:

Terminal window
TRUST_PROXY_HOPS=1
SMTP_HOST=smtp.example.com
EMAIL_FROM=noreply@example.com

The values under the virvi service’s environment: (mode, database, storage paths) win over .env. The full list is in Environment Variables.

Then apply it:

Terminal window
docker compose -f docker-compose.single.yml up -d

Scalable mode

docker-compose.scalable.yml runs two Virvi servers, virvi-1 and virvi-2, with Postgres, Redis and a Caddy proxy in front of them on host port ${PORT:-3010}. Redis (REDIS_URL=redis://redis:6379) shares real-time rooms between the servers. It has no password, so its port 6379 is published on 127.0.0.1 only.

Terminal window
docker compose -f docker-compose.scalable.yml up -d --build

How requests reach the servers. A real-time room lives on one server, so a visitor has to reach that server. Each server has its own path, set by ROOM_SERVER_PATH (/n1, /n2). It tells visitors that path when they join a room, and Caddy sends that path to that server only. Everything else (the dashboard, the API, joining a room) can go to either server, and Caddy takes turns between them. The routes are in deploy/caddy/Caddyfile.scalable.

docker compose up --scale doesn’t work with this file, because each server needs its own path. To add a server:

  1. In the Compose file, copy the virvi-2 service as virvi-3, with ROOM_SERVER_PATH: /n3.
  2. In deploy/caddy/Caddyfile.scalable, add a handle_path /n3/* block for virvi-3:3010, and add virvi-3:3010 to the shared reverse_proxy line.
  3. Run docker compose -f docker-compose.scalable.yml up -d.

HTTPS. Caddy serves plain HTTP on the published port. Either put your HTTPS proxy in front of it and set TRUST_PROXY_HOPS=2 in .env (your proxy and Caddy), or give Caddy your domain in place of :80 so it gets a certificate itself, and publish ports 80 and 443. With Caddy alone in front, keep the default TRUST_PROXY_HOPS=1.

If your servers aren’t all behind one address, set COLYSEUS_PUBLIC_ADDRESS on each instead, to the host (and path) where visitors reach that server, such as rooms-1.example.com.

Other things to know:

  • All containers share the uploads volume, so local storage works only while they run on one Docker host. Across hosts, use STORAGE_PROVIDER=s3 or r2.
  • Scene imports need SCENE_IMPORT_S3_URI in scalable mode; the scalable file has no private volume.
  • /metrics is served only with METRICS_TOKEN set, and a scraper must send it as Authorization: Bearer <token>.
  • Every server syncs the database schema when it starts. virvi-2 waits until virvi-1 is healthy, so they don’t sync at the same time.

Live streaming

Live streaming needs the separate media server in apps/streaming (RTMP in, HLS out). It isn’t in the Compose files.

Build and run it:

Terminal window
docker build -f apps/streaming/Dockerfile -t virvi-streaming .
docker run -d --name virvi-streaming \
-p 1935:1935 -p 8000:8000 \
-e VIRVI_API_URL=http://<virvi-server-host>:3010 \
-e VIRVI_WEBHOOK_KEY=<shared-secret> \
-v virvi-streams:/data/streams \
virvi-streaming
Media server variableDefaultWhat it does
VIRVI_API_URLhttp://localhost:3010The Virvi server it checks stream keys with
VIRVI_WEBHOOK_KEYnoneShared secret; must equal the server’s STREAMING_WEBHOOK_KEY
RTMP_PORT1935RTMP ingest port
HTTP_PORT8000HLS playback port (/streams/<playbackId>/playlist.m3u8)
OUTPUT_DIR/data/streams in the imageWhere HLS segments are written
MAX_STREAMS4Most streams transcoded at once
ENABLE_ABRofftrue transcodes several qualities
FFMPEG_PATHffmpegFFmpeg binary (included in the image)

Then set on the Virvi server: ENABLE_STREAMING=true, STREAMING_WEBHOOK_KEY (the same secret), RTMP_INGEST_URL (for example rtmp://stream.example.com:1935/live) and HLS_BASE_URL (for example https://stream.example.com/streams, behind HTTPS).

Development

docker-compose.dev.yml starts Postgres (user and password vlm / vlm_dev), Redis and MinIO (console on port 9001, vlm_dev / vlm_dev_secret). Run the server and dashboard yourself: see Quickstart.

Terminal window
docker compose -f docker-compose.dev.yml up -d

Stop and remove

Terminal window
docker compose -f docker-compose.single.yml down # stop; data volumes stay
docker compose -f docker-compose.single.yml down -v # stop and DELETE the database and uploads