Docker Swarm Resource Configuration#
Dokploy exposes four Docker Swarm resource knobs for each service — Memory Limit, Memory Reservation, CPU Limit, and CPU Reservation — through a shared UI component and a server-side conversion function. Understanding the raw numeric format these fields require is critical, because the documented units (MB/GB, CPU cores) differ from what is actually stored and sent to the Docker API.
Data Model#
All four fields are stored as nullable text strings in the database and validated as z.string().optional() in the tRPC layer . They appear on every deployable service type: application, postgres, mysql, mariadb, mongo, redis, and libsql.
| Field | Docker API field | Unit stored in DB |
|---|---|---|
memoryLimit | Limits.MemoryBytes | Bytes (integer, as string) |
memoryReservation | Reservations.MemoryBytes | Bytes (integer, as string) |
cpuLimit | Limits.NanoCPUs | Nanosecond-CPUs (integer, as string) |
cpuReservation | Reservations.NanoCPUs | Nanosecond-CPUs (integer, as string) |
The Format Mismatch#
Caution: Despite UI tooltips describing values in human-readable terms ("1GB", "2 CPUs"), what is stored in the database and passed to Docker is always a raw integer string.
- Memory: stored as bytes. 1 GB =
"1073741824", 256 MB ="268435456". - CPU: stored as NanoCPUs (10⁻⁹ of a CPU). 2 CPUs =
"2000000000", 1 CPU ="1000000000".
The docs page at Advanced settings describes values in user-friendly units, but the underlying API and database deal exclusively with these raw integers.
UI Component: ShowResources#
ShowResources (apps/dokploy/components/dashboard/application/advanced/show-resources.tsx) renders the Resources card for all service types. It is parameterized by { id, type } and uses a queryMap/mutationMap pattern to dispatch the correct tRPC query and mutation for each service type .
Each field uses the NumberInputWithSteps component (apps/dokploy/components/ui/number-input.tsx), which provides +/- step buttons and a live human-readable display beneath the raw input:
- Memory fields: step = 256 MB increments;
memoryConverteruses multiplier1024 * 1024(bytes → MB) and displays as MB or GB . - CPU fields: step = 0.25 CPU increments;
cpuConverteruses multiplier1_000_000_000(nanosecond-CPUs → CPUs) and displays asN CPU.
The createConverter factory bridges raw strings (stored in DB) ↔ numeric values (used in UI math) ↔ formatted display strings (shown to users):
toValue(raw):parseInt(raw) / multiplierfromValue(value):String(Math.round(value * multiplier))— this is what gets saved.formatDisplay(value): formats for display only, never persisted.
Users can also type the raw integer directly into the input field, which is the only input method when not using the step buttons .
After saving, users must Redeploy the service for changes to take effect .
Server-Side Conversion: calculateResources#
calculateResources (packages/server/src/utils/docker/utils.ts) converts the string fields into the ResourceRequirements object that Dockerode passes to docker service create/update:
MemoryBytes = parseInt(memoryLimit)
NanoCPUs = parseInt(cpuLimit)
It simply calls Number.parseInt() on each non-null string — no unit conversion happens here . This is why the values must already be in the correct raw units before reaching this function.
calculateResources is called inside mechanizeDockerContainer in packages/server/src/utils/builders/index.ts, which assembles the full service spec before calling docker.createService() or service.update().
Quick Reference: Common Values#
| Human Value | memoryLimit / memoryReservation string |
|---|---|
| 256 MB | 268435456 |
| 512 MB | 536870912 |
| 1 GB | 1073741824 |
| 2 GB | 2147483648 |
| Human Value | cpuLimit / cpuReservation string |
|---|---|
| 0.25 CPU | 250000000 |
| 0.5 CPU | 500000000 |
| 1 CPU | 1000000000 |
| 2 CPUs | 2000000000 |
Key Source Files#
| File | Purpose |
|---|---|
show-resources.tsx | UI form for all resource fields + ulimits |
number-input.tsx | NumberInputWithSteps + createConverter |
utils.ts (calculateResources) | String → Docker ResourceRequirements conversion |
builders/index.ts | Calls calculateResources during service deploy |