Cattleman Sockets for local development - Pusher-compatible WebSockets, as on Cloudflare
416
Cattleman Sockets for local development: Pusher-compatible WebSockets, run on your machine as they run on Cloudflare.
Sockets is a realtime server that speaks the Pusher protocol, deployed through Cattleman as a Cloudflare Worker. This image is for building an app against it without a deployment: pusher-js, Laravel Echo and the Pusher server SDKs connect to it as they would to your worker.
It isn't an imitation. The image runs the worker bundle Cattleman deploys, in workerd, the runtime Cloudflare runs it in. The protocol, error codes, limits and webhook signatures are the ones you get in production.
docker run --rm -p 6001:6001 cattleman/sockets
It starts with one app and prints the lines for your app's .env:
CATTLEMAN_APP_ID=app-id
CATTLEMAN_APP_KEY=app-key
CATTLEMAN_APP_SECRET=app-secret
CATTLEMAN_HOST=localhost
CATTLEMAN_PORT=6001
CATTLEMAN_SCHEME=http
A browser client connects with pusher-js:
const pusher = new Pusher("app-key", {
wsHost: "localhost",
wsPort: 6001,
forceTLS: false,
enabledTransports: ["ws"],
cluster: "",
});
GET /ready answers {"ok":true} for health checks, and the image has a
HEALTHCHECK that uses it.
services:
sockets:
image: cattleman/sockets:1
ports:
- "6001:6001"
environment:
SOCKETS_APP_ID: my-app
SOCKETS_APP_KEY: my-key
SOCKETS_APP_SECRET: my-secret
app:
# ...
depends_on:
sockets:
condition: service_healthy
From another Compose service the host is the service name (sockets);
from a browser on your machine it is localhost.
Settings are environment variables. The limits are the ones on a deployment's settings page in Cattleman, with the same defaults and ranges.
| Variable | Default | |
|---|---|---|
SOCKETS_APP_ID | app-id | The app's id |
SOCKETS_APP_KEY | app-key | The app's key |
SOCKETS_APP_SECRET | app-secret | The app's secret |
SOCKETS_WEBHOOKS | [] | The app's webhooks, as a JSON list |
SOCKETS_APPS_FILE | A JSON file of apps, in place of the four above | |
SOCKETS_PORT | 6001 | Port to listen on |
SOCKETS_DEBUG | false | Log connections, subscriptions, events and webhooks (below) |
SOCKETS_MAX_CONNECTIONS | 1000000 | Concurrent connections (1-10000000) |
SOCKETS_ENABLE_CLIENT_MESSAGES | true | Allow client-* events on private and presence channels |
SOCKETS_CLUSTER_MODE | false | Spread connections across shards |
SOCKETS_CLUSTER_CONNECTIONS_PER_SHARD | 600 | Connections per shard in cluster mode (100-10000) |
SOCKETS_MAX_BACKEND_EVENTS_PER_SECOND | 10 | Events through the REST API per second (1-1000) |
SOCKETS_MAX_CLIENT_EVENTS_PER_SECOND | 100 | Client events per second, per connection (1-1000) |
SOCKETS_MAX_READ_REQUESTS_PER_SECOND | 10 | REST API reads per second (1-1000) |
SOCKETS_MAX_PRESENCE_MEMBERS_PER_CHANNEL | 100 | Members in one presence channel (1-1000) |
SOCKETS_MAX_PRESENCE_MEMBER_SIZE_IN_KB | 10 | Size of one presence member's data (1-100) |
SOCKETS_MAX_CHANNEL_NAME_LENGTH | 200 | Channel name length (50-500) |
SOCKETS_MAX_EVENT_CHANNELS_AT_ONCE | 10 | Channels one event may target (1-100) |
SOCKETS_MAX_EVENT_NAME_LENGTH | 200 | Event name length (50-500) |
SOCKETS_MAX_EVENT_PAYLOAD_IN_KB | 300 | Event payload size (10-1000) |
SOCKETS_MAX_EVENT_BATCH_SIZE | 10 | Events in one batch_events request (1-100) |
A value that isn't valid stops the server before it starts, and says why.
docker run --rm cattleman/sockets --help lists the settings of the
version you have.
Mount a JSON file and point SOCKETS_APPS_FILE at it. Each app can set its
own limits and webhooks; the two cluster settings apply to the whole server.
[
{ "id": "shop", "key": "shop-key", "secret": "shop-secret" },
{ "id": "chat", "key": "chat-key", "secret": "chat-secret", "enableClientMessages": false }
]
docker run --rm -p 6001:6001 \
-v ./apps.json:/etc/sockets/apps.json:ro \
-e SOCKETS_APPS_FILE=/etc/sockets/apps.json \
cattleman/sockets
docker run --rm -p 6001:6001 \
-e SOCKETS_WEBHOOKS='[{"url":"http://host.docker.internal:8000/pusher/webhooks","event_types":["channel_occupied","channel_vacated"]}]' \
cattleman/sockets
event_types takes channel_occupied, channel_vacated, member_added,
member_removed, client_event and cache_miss. An optional
"filter": { "channel_name_starts_with": "presence-" } limits a webhook to
matching channels. Requests are signed as in production, with
X-Pusher-Key and X-Pusher-Signature.
Webhooks are sent from inside the container. Address an app in the same
Compose project by its service name, and one running on your machine by
host.docker.internal (on Linux, add
--add-host=host.docker.internal:host-gateway).
Set SOCKETS_DEBUG=1 and the server logs a line for each connection,
subscription, published event and webhook, and says why anything was
refused:
docker run --rm -p 6001:6001 -e SOCKETS_DEBUG=1 cattleman/sockets
14:02:11.531 [app-id] 5197641.2897028 connected
14:02:11.642 [app-id] 5197641.2897028 subscribed to private-orders
14:02:12.001 [app-id] POST /apps/app-id/events: 200
14:02:12.003 [app-id] published order.shipped on private-orders to 1 connection
14:02:12.330 [app-id] 5197641.2897028 sent client-typing on private-orders
14:02:12.334 [app-id] webhook client_event to http://app/pusher/webhooks: 200
14:02:15.120 [app-id] 8802193.5512907 was refused private-orders: The connection is unauthorized. (401)
14:02:16.004 [app-id] POST /apps/app-id/events: 401 The request signature is invalid.
14:02:20.918 [app-id] 5197641.2897028 disconnected
Each line starts with the time (UTC) and the app, and a connection is named
by its socket id. published ... to nobody means the event was accepted
but no connection was subscribed to that channel. Event payloads aren't
logged, and nor are health checks.
ws:// and http://, where a deployment is wss://
and https:// on port 443.The image's version is the worker's: cattleman/sockets:1.2.1 runs the
1.2.1 worker, so you can develop against the version your deployment is on.
1.2 and 1 follow the newest patch and minor release, and latest the
newest release. Images are built for linux/amd64 and linux/arm64.
Sockets is a derivative of soketi and
is licensed under the
GNU Affero General Public License v3.
The image contains the source it was built from, in /app, with the
licence text in /app/LICENSE:
docker run --rm --entrypoint tar cattleman/sockets -c -C /app --exclude=node_modules . > sockets-source.tar
Content type
Image
Digest
sha256:4ddcc810a…
Size
123.4 MB
Last updated
about 2 hours ago
docker pull cattleman/sockets