Reverb
Run Laravel Reverb, Laravel's WebSocket server, as its own container from the same image as your web service. Unlike the other workers, Reverb listens on a port, so your reverse proxy needs a route to it.
Install and configure Reverb in your application first, following Laravel's Reverb docs. The stop signal and health check follow the same rules as every other worker. See Running workers.
Compose example with Traefik
This example routes app.example.com to the web service on port 8080 and reverb.example.com to Reverb on port 8000.
services:
app:
image: my-org/my-app:1.0.0
labels:
- "traefik.enable=true"
- "traefik.http.routers.laravel.tls=true"
- "traefik.http.routers.laravel.entrypoints=websecure"
- "traefik.http.routers.laravel.rule=Host(`app.example.com`)"
- "traefik.http.services.laravel.loadbalancer.server.port=8080"
- "traefik.http.services.laravel.loadbalancer.server.scheme=http"
reverb:
image: my-org/my-app:1.0.0
command: ["php", "artisan", "reverb:start", "--port=8000"]
stop_signal: SIGTERM
healthcheck:
test: ["CMD", "healthcheck-reverb"]
start_period: 10s
labels:
- "traefik.enable=true"
- "traefik.http.routers.reverb.tls=true"
- "traefik.http.routers.reverb.entrypoints=websecure"
- "traefik.http.routers.reverb.rule=Host(`reverb.example.com`)"
- "traefik.http.services.reverb.loadbalancer.server.port=8000"
- "traefik.http.services.reverb.loadbalancer.server.scheme=http"
Client variables point at the proxy, not the container
Reverb reads two sets of variables. The REVERB_SERVER_* variables configure the Reverb process inside the container. The REVERB_HOST, REVERB_PORT, and REVERB_SCHEME variables tell clients where to connect: browsers, and your application when it broadcasts an event. They must match the public address that Traefik serves.
| Variable | Value for the example above |
|---|---|
REVERB_HOST | reverb.example.com |
REVERB_PORT | 443 |
REVERB_SCHEME | https |
Don't set REVERB_PORT to 8000. Clients would then connect to the container port, which Traefik doesn't expose.