Your 2 GB VPS did not fall over because of traffic. It fell over because Nextcloud, PostgreSQL, Redis, and a reverse proxy all booted at once, each assuming it was the only tenant on the box. The Linux OOM killer picked a victim at 03:14, and you spent the next morning reading dmesg instead of shipping anything.

Sizing is the least glamorous part of self-hosting and the one that decides whether your stack survives contact with reality. Below are the numbers that matter: what each project’s documentation actually requires, what it needs once you enable the features you bought the server for, and how to enforce those numbers with Compose limits so one runaway container cannot take down the other seventeen.

TL;DR — the 60-second verdict

If you are running a handful of lightweight services (Vaultwarden, Uptime Kuma, Caddy, Gitea), a 2 GB / 2 vCPU box is genuinely enough. If Immich or Jellyfin is in the stack, start at 8 GB and plan for storage growth, not CPU. If you are running mailcow, treat 6 GB as a floor, not a target — its own documentation says so. Everything else in between fits comfortably in 4 GB. The mistake almost everyone makes is sizing for the applications and forgetting the databases, caches, and reverse proxy that come with them, which together routinely add 1–2 GB.

The sizing table: 18 services, documented floor vs realistic number

“Minimum RAM” in a README usually means “the process starts.” It does not mean “the process is usable.” The table below separates the two, using vendor documentation as the floor and real deployment experience for the working figure.

ServiceDocumented floorRealistic working setCPUDisk driverStar count (Nov 2026)
Nextcloud512 MB2–4 GB2 vCPUuser files + previews37,557
Immich4 GB8–12 GB4 vCPUphoto/video originals + thumbnails119,622
Gitea512 MB1–2 GB2 vCPUGit objects + LFS59,163
Grafana512 MB1 GB1 vCPUtime-series retention77,989
Paperless-ngx1 GB2–4 GB2 vCPUscanned PDFs + OCR cache48,324
Vaultwarden128 MB256–512 MB1 vCPUtiny (attachments grow slowly)70,995
mailcow6 GB8–12 GB4 vCPUmailboxes + search index13,843
Jellyfin2 GB4–8 GB4 vCPU (transcodes)media library59,537
Home Assistant2 GB2–4 GB2 vCPUrecorder DB grows fast92,376
n8n2 GB4 GB2 vCPUexecution history211,374
Uptime Kuma128 MB256 MB1 vCPUheartbeat history (prunes)94,624
Wiki.js512 MB1 GB1 vCPUpage revisions29,333
Authelia128 MB256 MB1 vCPUnegligible29,684
Caddy64 MB128–256 MB1 vCPUcertificates only79,258
Traefik64 MB128–256 MB1 vCPUaccess logs (optional)65,602
PostgreSQL 171 GB2–4 GB2 vCPUWAL + heap + indexes— (distro package)
Redis / Valkey128 MB512 MB–1 GB1 vCPUin-memory only—
MinIO512 MB1–2 GB2 vCPUobject storage, scales with data— (AGPL, source-only distribution)

Two columns are worth staring at: Immich and mailcow. Immich is not a photo browser; it is a photo pipeline. Its own documentation asks for 4 GB minimum and recommends more, because thumbnail generation, face detection, and video transcoding all run alongside the API. mailcow bundles Postgres, Redis, Dovecot, Postfix, Rspamd, ClamAV, and Solr — a 4 GB box will boot it, then quietly swap itself to death under spam filtering.

Decision matrix: pick a server size in ten seconds

Your use caseRecommended hardwareWhy
Password vault, uptime checks, reverse proxy, a wiki2 GB / 2 vCPU / 40 GB SSDAll four together idle under 700 MB
Git hosting, CI runner, small Postgres, monitoring4 GB / 2 vCPU / 80 GB SSDGit + Postgres shared buffers + Grafana fit with headroom
Photo library, document archive, automation8 GB / 4 vCPU / 160 GB SSDImmich and Paperless both spike during imports
Media server with transcoding8–16 GB / 4–8 vCPU, or a used mini PC with Quick SyncSoftware transcodes eat cores; hardware transcode changes the math
Full mail server for a small domain8 GB / 4 vCPU / 80 GB SSDmailcow plus its anti-spam stack
Everything above on one host32 GB / 8 vCPU, and stop pretending it is one hostYou now need per-container limits, not hope

Where the memory actually goes

Three multipliers explain almost every “my stack needs more than the docs said” surprise.

Workers multiply the base process. Gitea with 4 workers, Nextcloud with 8 PHP-FPM children, and Paperless with a 4-thread OCR queue each cost roughly per worker, not per service. A PHP-FPM child running Nextcloud typically holds 60–120 MB. Eight of them is a gigabyte before the database does anything.

Database caches want to be large. PostgreSQL’s default shared_buffers is small, but the moment you tune it to 25% of RAM — the usual advice — your database’s appetite scales with the host. On a 4 GB box, a 1 GB shared_buffers plus work_mem across concurrent queries is a real allocation, not a hint.

Media work is bursty and invisible. Thumbnailers, transcode jobs, and OCR workers allocate in spikes. Averages look fine; the 30 seconds after an upload does not. This is why sizing on docker stats averages fails and sizing on peaks works.

For a deeper look at the proxy layer that sits in front of all of this, see our reverse proxy management comparison. If you want to watch memory and uptime trends over time, the synthetic monitoring guide covers the alerting side, and PostgreSQL performance dashboards explains how to see what the database is doing with its share of RAM.

Immich: the service that punishes optimistic sizing

Immich is the clearest example of documented floors diverging from real usage, and it is worth walking through because the same pattern applies to Paperless and Jellyfin.

Immich photo library interface

The API server itself is modest — a few hundred megabytes. The cost arrives with the background jobs: thumbnail generation, video transcoding, and the recognition pipeline. On an 8 GB host with 4 vCPU, a first import of 40,000 photos will happily saturate every core for hours and push resident memory past 6 GB. On a 4 GB host, that same import triggers the OOM killer, and the container restarts mid-job — repeatedly, because the job queue resumes and re-triggers the spike.

The fix is not “buy more RAM” alone; it is bounding the workers. Immich exposes concurrency controls, and Compose can cap the container so a runaway job kills itself instead of the host:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
services:
  immich-server:
    image: ghcr.io/immich-app/immich-server:v1
    restart: unless-stopped
    env_file: .env
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
    ports:
      - "2283:2283"
    depends_on:
      - redis
      - database
    deploy:
      resources:
        limits:
          memory: 6g
        reservations:
          memory: 2g

  database:
    image: ghcr.io/immich-app/postgres:14-vectorchord0.4.3-pgvectors0.2.0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: "--data-checksums"
    volumes:
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    shm_size: 128mb
    restart: unless-stopped

Note shm_size: PostgreSQL parallel query workers need shared memory beyond Docker’s 64 MB default, and starving them is a classic cause of “the database is slow for no reason” on self-hosted installs.

n8n: a Node runtime with opinions about heap

Node services are a separate failure mode. The runtime reserves heap generously, garbage collection is lazy, and a workflow engine that holds execution data in memory grows in steps rather than curves.

n8n workflow editor

On a 2 GB host, n8n will start and run a few workflows, then die the first time a workflow branches over a large JSON payload. The documented floor is around 2 GB; the practical figure for anything with more than a handful of active workflows is 4 GB. Constrain it explicitly, and set the heap ceiling so the process fails fast with a clear error instead of being killed by the kernel:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
services:
  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=n8n.example.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.example.com/
      - GENERIC_TIMEZONE=UTC
      - NODE_OPTIONS=--max-old-space-size=2048
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=168
    volumes:
      - n8n_data:/home/node/.n8n
    deploy:
      resources:
        limits:
          memory: 3g
volumes:
  n8n_data:

EXECUTIONS_DATA_PRUNE is not cosmetic. Execution history is the single largest table in most n8n installs, and it grows with every run of every workflow. Pruning it weekly is the difference between a 2 GB database and a 40 GB one eighteen months later.

Measuring what you actually use

Sizing without measurement is guessing with extra steps. Two commands cover most of it:

1
2
3
4
5
# Current and peak memory per container (peak is the number that matters)
docker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}\t{{.CPUPerc}}"

# Host-level OOM events, the definitive proof of under-sizing
dmesg -T | grep -iE "out of memory|oom-kill" | tail -20

Run the first during a realistic workload — an import, a backup, a transcode — not at idle. If a container’s peak sits within 15% of its limit, it is under-provisioned regardless of what the average says.

Pitfalls that cost people weekends

Setting limits without reservations. limits protects the host; reservations protects the service. A container with a 512 MB limit and no reservation gets scheduled like a 0 MB container and can be starved under contention.

Forgetting the reverse proxy and the database in the budget. These are always-on processes. Allocate 1–2 GB for the supporting cast before you divide the rest among applications.

Ignoring disk I/O as a sizing dimension. A 2 vCPU / 4 GB VPS with network-attached storage will bottleneck on fsync long before it runs out of RAM. PostgreSQL WAL writes and mail delivery are both latency-sensitive.

Treating swap as capacity. Swap converts an OOM kill into unpredictable latency. It is a cushion, not a plan. If a service routinely swaps, it is mis-sized.

Sizing once and never again. Photo libraries, mailboxes, and execution histories grow monotonically. Re-check docker stats peaks quarterly, or set an alert on host memory above 85% for an hour.

A sizing worksheet you can copy

Before you rent anything, write down the stack and add it up. This is the arithmetic that replaces intuition:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Base OS + Docker daemon .................. 400 MB
Reverse proxy (Caddy/Traefik) ............ 150 MB
PostgreSQL (shared_buffers 25% of 2 GB) .. 700 MB
Redis/Valkey ............................. 300 MB
Service A (Nextcloud, 6 FPM workers) ..... 1400 MB
Service B (Gitea) ........................ 700 MB
Service C (Uptime Kuma + Grafana) ........ 900 MB
Headroom for bursts and page cache ....... 1000 MB
--------------------------------------------------
Total .................................... ~5.5 GB  ->  buy 8 GB

If your total lands within 20% of a server size, buy the next size up. The cost difference between 4 GB and 8 GB is typically a few dollars a month; the cost of a migration at 2 a.m. is not.

FAQ

How much RAM do I need to run Docker Compose self-hosted services? For four to six lightweight services (reverse proxy, password vault, uptime monitor, Git host), 2 GB is workable. Add 2 GB for every database-backed application you enable, and 8 GB or more if photo management or media transcoding is involved.

Why does my container get killed when the host still shows free memory? The kernel OOM killer acts on cgroup limits and on memory pressure, not on free -h alone. Page cache inflates apparent usage, and a container with a low limit can be killed while the host looks comfortable. Check docker inspect limits and dmesg OOM lines together.

Is 4 GB enough for Nextcloud with a database? Barely, for a single user. Nextcloud’s documented floor is 512 MB, but PHP-FPM workers, preview generation, and PostgreSQL together push a realistic install to 2–4 GB. A 4 GB host works if you cap worker counts and disable heavy preview generation.

Should I use swap on a self-hosted VPS? Yes, as a safety cushion of 1–2 GB with vm.swappiness around 10, not as a substitute for capacity. Services that swap continuously will exhibit latency spikes and eventual OOM kills anyway.

How often should I re-check my sizing? Quarterly, and after any large import or new service. Peak memory during a real workload is the only reliable signal — idle averages hide the spikes that actually kill containers.


💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com