Docker and Compose
Run Sockudo in containers with mounted configuration, correct limits, health checks, and shared backends.
This guide runs the published Sockudo image with docker run or Docker Compose, with production
limits, read-only configuration, and separate secrets. Choose it for a single container host, for
staging environments, or as the building block before moving to
Kubernetes.
What the image does by default
The published image is built from the repository Dockerfile:
- it runs as a non-root
sockudouser with/appas the working directory - its default command is
sockudo --config /app/config/config.json - it exposes
6001(WebSocket and HTTP API) and9601(Prometheus metrics) - it sets
HOST=0.0.0.0,PORT=6001, andMETRICS_PORT=9601 - it includes
curland aHEALTHCHECKthat callshttp://localhost:${PORT}/${HEALTHCHECK_PATH}every 30 seconds, withHEALTHCHECK_PATH=up
The bundled config.json is a development example: mode is development, the adapter is
local, and shutdown_grace_period is 2 seconds. It lets a bare docker run start safely with
node-local drivers. For production, pin a release tag, mount or generate the exact configuration,
inject secrets separately, and set limits on the container itself.
The image is published to both ghcr.io/sockudo/sockudo and Docker Hub as sockudo/sockudo, with
the same version tags.
Production-like docker run
-
Put the non-secret configuration in
config.toml(see Static configuration) and the secrets insockudo.env. Make the config readable by the container user and keep the env file private:Terminal window chmod 0644 config.tomlchmod 0600 sockudo.env -
Start the container:
Terminal window docker run -d \--name sockudo \--restart unless-stopped \--init \--stop-timeout 120 \--ulimit nofile=262144:262144 \--read-only \--tmpfs /tmp:rw,noexec,nosuid,size=64m \--mount type=bind,src="$PWD/config.toml",dst=/app/config/production.toml,readonly \--env-file "$PWD/sockudo.env" \-e HEALTHCHECK_PATH=up/production \-p 6001:6001 \-p 127.0.0.1:9601:9601 \ghcr.io/sockudo/sockudo:5.3.0 \sockudo --config /app/config/production.toml -
Confirm the configuration source and health:
Terminal window docker logs sockudo 2>&1 | grep 'explicit configuration applied'curl -fsS http://127.0.0.1:6001/up/productiondocker inspect sockudo --format '{{.State.Health.Status}}'The log line names
/app/config/production.toml,curlprintsOK, and the health status becomeshealthyafter the first check.
Why each flag is there:
| Flag | Purpose |
|---|---|
sockudo --config ... after the image | Arguments after the image replace its default command, so include both sockudo and --config. |
--init | Runs a minimal init as PID 1 that forwards signals and reaps child processes. |
--stop-timeout 120 | Time between SIGTERM and SIGKILL; it must cover Sockudo’s drain (see below). |
--ulimit nofile=... | Raises the open-file limit; every WebSocket is a file descriptor. |
--read-only and --tmpfs /tmp | Makes the image filesystem immutable while leaving a small scratch area. Sockudo logs to stdout. |
-e HEALTHCHECK_PATH=up/production | Points the image’s built-in health check at your app. |
-p 127.0.0.1:9601:9601 | Publishes metrics only on loopback. |
The CONFIG_FILE environment value embedded in the image is descriptive; the server selects a
non-default file through --config.
Compose profile
This example keeps the Sockudo process immutable and connects it to an external or separately managed Redis:
name: sockudo
services: sockudo: image: ghcr.io/sockudo/sockudo:5.3.0 command: ["sockudo", "--config", "/app/config/production.toml"] restart: unless-stopped init: true stop_grace_period: 120s read_only: true tmpfs: - /tmp:size=64m,mode=1777 ulimits: nofile: soft: 262144 hard: 262144 ports: - "6001:6001" - "127.0.0.1:9601:9601" volumes: - ./config/production.toml:/app/config/production.toml:ro env_file: - ./secrets/sockudo.env environment: HOST: "0.0.0.0" PORT: "6001" METRICS_HOST: "0.0.0.0" METRICS_PORT: "9601" INSTANCE_PROCESS_ID: "compose-1" healthcheck: test: ["CMD", "curl", "-fsS", "http://127.0.0.1:6001/up/production"] interval: 10s timeout: 3s start_period: 20s retries: 3 logging: driver: local options: max-size: "20m" max-file: "5"Start it and check the result:
docker compose up -ddocker compose psThe sockudo service shows running (healthy) once /up/production returns OK.
METRICS_HOST is 0.0.0.0 inside the container so the published port can reach the metrics
listener; the 127.0.0.1:9601 host binding is what keeps it private.
For local development, adding Redis to the same Compose project is convenient. In production, a single-host Redis container has the same host failure domain as Sockudo. Use a managed or independently operated Redis topology when the shared adapter, cache, queue, or rate limiter must survive that host.
Configuration and secrets
Prefer this separation:
- mount the complete non-secret TOML or JSON read-only
- supply secret-backed environment variables through the orchestrator
- reference those variables from the config with
${VAR}placeholders when a nested value, such as an inline app secret, has no dedicated environment variable - mount TLS keys, provider credentials, and service-account JSON as read-only secret files
- reference secret file paths from Sockudo configuration or environment
An env_file is still a plaintext secret file on the Docker host. Limit its owner and mode, keep it
out of image build context and source control, and rotate it through the host’s secret-management
workflow.
Limits: host versus container
Three different layers can cap a container:
| Layer | Check | Configure |
|---|---|---|
| Sockudo admission | SOCKUDO_MAX_CONNECTIONS | Static config or environment |
Process nofile | docker exec sockudo sh -c 'ulimit -n' | --ulimit or Compose ulimits |
| Host kernel and service manager | sysctl, Docker daemon unit limits | Host image, sysctl, and daemon configuration |
The lowest of the three wins. Changing /etc/security/limits.d inside the image does not raise the
running container’s file limit. Set it through the runtime and verify from inside the container.
Host-level connection queues and NIC settings remain host concerns. Namespaced sysctls may be set per container, but only after confirming the runtime supports them and the value is safe for other workloads. For a dedicated container host, apply the measured host guidance from Linux VM and bare metal.
CPU and memory
Start with a memory limit that leaves room for peak sockets, payload buffers, adapter queues, and allocator fragmentation. An out-of-memory kill disconnects every client on that container at once, and they all reconnect at the same moment.
CPU quotas can create latency cliffs during reconnect or fanout bursts. Set CPU reservations, watch throttling metrics, and add a hard CPU limit only when multi-tenant isolation requires one and the load test includes the same quota.
Measure:
docker stats sockudodocker inspect sockudo --format '{{json .HostConfig.Ulimits}}'docker exec sockudo sh -c 'ulimit -n; cat /proc/1/limits'docker exec sockudo sh -c 'curl -fsS -o /dev/null -w "%{http_code}\n" http://127.0.0.1:6001/live'ulimit -n must print 262144, and the /live check prints 200.
Health and startup ordering
Use /live when the runtime needs to decide whether the process is alive. Use /up or
/up/<app-id> when the load balancer needs dependency-aware readiness. /up/<app-id> prints OK
with status 200 when healthy and returns 503 when a dependency check fails.
Compose depends_on can order startup, but it does not make a dependency permanently available.
Sockudo must still expose failed readiness and operators must alert on adapter, cache, queue, and
app-manager failures.
Multi-host containers
Moving Compose services onto two VMs does not create Sockudo clustering automatically. Every Sockudo replica must have:
- the same app identity and policy, or access to one shared app manager
- a unique
INSTANCE_PROCESS_ID - a shared horizontal adapter with
fallback_to_local = false - a shared cache for cross-node coordination and distributed limits
- durable queue and state backends where the enabled features require them
- a WebSocket-aware load balancer with readiness and connection drain
Do not place a local memory adapter behind a multi-host load balancer. Clients connected to different hosts would occupy isolated realtime islands.
Production checklist
- the image tag is a pinned release, never
latest - logs show
explicit configuration appliedwith your mounted path ulimit -ninside the container matches the intendednofile- the stop timeout exceeds
shutdown_grace_periodplus twice the queue shutdown timeout - the metrics port is bound to loopback or a private network
- secrets live only in the env file or mounted secret files, never in the image or command line
- multi-host deployments use a shared adapter, cache, and queue