# Docker and Compose (https://sockudo.io/docs/deployment/docker)
> 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](/docs/deployment/kubernetes).
## What the image does by default
The published image is built from the repository `Dockerfile`:
- it runs as a non-root `sockudo` user with `/app` as the working directory
- its default command is `sockudo --config /app/config/config.json`
- it exposes `6001` (WebSocket and HTTP API) and `9601` (Prometheus metrics)
- it sets `HOST=0.0.0.0`, `PORT=6001`, and `METRICS_PORT=9601`
- it includes `curl` and a `HEALTHCHECK` that calls `http://localhost:${PORT}/${HEALTHCHECK_PATH}`
every 30 seconds, with `HEALTHCHECK_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
1. Put the non-secret configuration in `config.toml` (see
[Static configuration](/docs/deployment/static-configuration)) and the secrets in
`sockudo.env`. Make the config readable by the container user and keep the env file private:
```bash
chmod 0644 config.toml
chmod 0600 sockudo.env
```
2. Start the container:
```bash
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.2.0 \
sockudo --config /app/config/production.toml
```
3. Confirm the configuration source and health:
```bash
docker logs sockudo 2>&1 | grep 'explicit configuration applied'
curl -fsS http://127.0.0.1:6001/up/production
docker inspect sockudo --format '{{.State.Health.Status}}'
```
The log line names `/app/config/production.toml`, `curl` prints `OK`, and the health status
becomes `healthy` after 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`.
Docker's default stop timeout is 10 seconds. After `SIGTERM`, Sockudo keeps its listener open for
`shutdown_grace_period`, then drains webhooks and queue work, each phase bounded by
`queue.reliability.shutdown_timeout_ms` (30 seconds by default). With
`shutdown_grace_period = 30` that is up to `30 + 2 × 30 = 90` seconds before teardown, so the
examples use 120 seconds. A `SIGKILL` during the drain can lose buffered lifecycle events.
## Compose profile
This example keeps the Sockudo process immutable and connects it to an external or separately
managed Redis:
```yaml title="compose.yaml"
name: sockudo
services:
sockudo:
image: ghcr.io/sockudo/sockudo:5.2.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:
```bash
docker compose up -d
docker compose ps
```
The `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.
Docker build arguments and layers can remain visible in image metadata or caches. Inject
credentials at runtime only.
## 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](/docs/deployment/linux).
## 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:
```bash
docker stats sockudo
docker 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/` when the load balancer needs dependency-aware readiness. `/up/` 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.
Plain Docker and Compose report a failing health check as `unhealthy` but do not restart the
container because of it. That is the right behavior for a dependency-aware check: restarting a
healthy process because Redis is briefly slow does not repair Redis and amplifies reconnect load.
If you add an auto-restart tool, point it at `/live`, not `/up`.
## 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 applied` with your mounted path
- `ulimit -n` inside the container matches the intended `nofile`
- the stop timeout exceeds `shutdown_grace_period` plus 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
## Next steps
- [Kubernetes and Helm](/docs/deployment/kubernetes): Move from one container host to orchestrated replicas.
- [Linux VM and bare metal](/docs/deployment/linux): Tune the container host's kernel and network path.
- [Static configuration](/docs/deployment/static-configuration): Write the config file you mount into the container.
- [Scaling](/docs/server/scaling): Choose a shared adapter before adding a second host.