DEV Community

konsongong
konsongong

Posted on Originally published at vpsfolio.com

Self-Host Paperless-ngx with Docker: Secure Document Archive

Measured Sandbox Benchmark

Idle RAM Startup Containers Recommended VPS
654.2 MB 110.8s 3 2 GB VPS

Per-container RAM: webserver 615.3 MB · db 30.6 MB · broker 8.3 MB (sandbox verified 2026-11-24)

View the interactive benchmark plate and full VPS sizing comparison or compare all measured stacks on VPSFolio Benchmarks.


What Paperless-ngx does and what it needs

Paperless-ngx turns scanned PDFs and images into a searchable, tagged archive. It runs OCR (via Tesseract), indexes text, and gives you a web UI plus a REST API. The official stack is three services: the Paperless web/worker container, PostgreSQL, and Redis. For OCR on office formats and PDF/A conversion, the upstream compose also includes Gotenberg and Apache Tika. This guide wires all five together with named volumes and no host bind mounts.

The project does not publish a minimum RAM figure. Idle memory is modest; OCR and PDF/A conversion spike CPU and RAM per document. Size for concurrent ingestion and the size of your scans, not for a fixed number.

Prerequisites, ports, and volume constraints

  • Docker Engine 24+ and the Compose v2 plugin.
  • A domain (or localhost) and a reverse proxy for TLS. Paperless stores sensitive documents in clear text; never expose it on an untrusted network.
  • Host port 8000 is the documented web port. Bind it to 127.0.0.1 so only the proxy reaches it.
  • Persistent data lives in four named volumes: paperless_data (SQLite fallback and app state), paperless_media (original and archived documents), paperless_pgdata (PostgreSQL), and paperless_redisdata (Redis AOF). Back up paperless_media and paperless_pgdata together; they are the source of truth.
  • The container runs as UID/GID 1000 by default. If your host user differs, set USERMAP_UID and USERMAP_GID in .env to match ownership of the volumes.

Production Docker Compose setup

Create the project directory and the environment file. Generate real secrets; do not reuse example values.

mkdir -p ~/paperless-ngx && cd ~/paperless-ngx
cat <<'EOF' > .env
# --- Core ---
TZ=UTC
PAPERLESS_URL=https://paperless.example.com
PAPERLESS_PORT=8000
PAPERLESS_ADMIN_USER=admin
PAPERLESS_ADMIN_PASSWORD=REPLACE_WITH_OPENSSL_RAND_HEX_32
PAPERLESS_SECRET_KEY=REPLACE_WITH_OPENSSL_RAND_HEX_32
# --- Database ---
POSTGRES_DB=paperless
POSTGRES_USER=paperless
POSTGRES_PASSWORD=REPLACE_WITH_OPENSSL_RAND_HEX_32
# --- Optional tuning ---
PAPERLESS_OCR_LANGUAGE=eng
PAPERLESS_TIME_ZONE=UTC
USERMAP_UID=1000
USERMAP_GID=1000
EOF

# Fill the three REPLACE_WITH_OPENSSL_RAND_HEX_32 placeholders
sed -i "s|REPLACE_WITH_OPENSSL_RAND_HEX_32|$(openssl rand -hex 32)|g" .env
Enter fullscreen mode Exit fullscreen mode

Now write compose.yml. It mirrors the upstream service layout: web, worker, PostgreSQL, Redis, Gotenberg, and Tika. Only the web port is published, and only on loopback.

cat <<'EOF' > compose.yml
services:
  broker:
    image: docker.io/library/redis:7-alpine
    restart: unless-stopped
    volumes:
      - paperless_redisdata:/data
    command: redis-server --appendonly yes
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

  db:
    image: docker.io/library/postgres:16-alpine
    restart: unless-stopped
    volumes:
      - paperless_pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-paperless}
      POSTGRES_USER: ${POSTGRES_USER:-paperless}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-paperless} -d ${POSTGRES_DB:-paperless}"]
      interval: 10s
      timeout: 5s
      retries: 10

  webserver:
    image: ghcr.io/paperless-ngx/paperless-ngx:latest
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
      broker:
        condition: service_healthy
    ports:
      - "127.0.0.1:8000:8000"
    volumes:
      - paperless_data:/usr/src/paperless/data
      - paperless_media:/usr/src/paperless/media
      - paperless_export:/usr/src/paperless/export
      - paperless_consume:/usr/src/paperless/consume
    environment:
      PAPERLESS_REDIS: redis://broker:6379
      PAPERLESS_DBHOST: db
      PAPERLESS_DBENGINE: postgresql
      PAPERLESS_DBNAME: ${POSTGRES_DB:-paperless}
      PAPERLESS_DBUSER: ${POSTGRES_USER:-paperless}
      PAPERLESS_DBPASS: ${POSTGRES_PASSWORD}
      PAPERLESS_URL: ${PAPERLESS_URL:-http://127.0.0.1:8000}
      PAPERLESS_ALLOWED_HOSTS: ${PAPERLESS_ALLOWED_HOSTS:-localhost,127.0.0.1}
      PAPERLESS_SECRET_KEY: ${PAPERLESS_SECRET_KEY}
      PAPERLESS_ADMIN_USER: ${PAPERLESS_ADMIN_USER:-admin}
      PAPERLESS_ADMIN_PASSWORD: ${PAPERLESS_ADMIN_PASSWORD}
      PAPERLESS_OCR_LANGUAGE: ${PAPERLESS_OCR_LANGUAGE:-eng}
      PAPERLESS_TIME_ZONE: ${PAPERLESS_TIME_ZONE:-UTC}
      USERMAP_UID: ${USERMAP_UID:-1000}
      USERMAP_GID: ${USERMAP_GID:-1000}

volumes:
  paperless_data:
  paperless_media:
  paperless_export:
  paperless_consume:
  paperless_pgdata:
  paperless_redisdata:
EOF
Enter fullscreen mode Exit fullscreen mode

Start the stack and watch the logs for the initial migration and admin creation.

docker compose up -d
docker compose logs -f webserver
Enter fullscreen mode Exit fullscreen mode

Reverse proxy, HTTPS, and first-run hardening

Paperless needs PAPERLESS_URL to match the public URL exactly, including scheme. If it does not, generated links and CSRF checks fail. Set it to https://paperless.example.com before first boot.

Caddy example (separate from the compose file):

paperless.example.com {
    encode zstd gzip
    request_body {
        max_size 100MB
    }
    reverse_proxy 127.0.0.1:8000 {
        header_up X-Forwarded-Proto {scheme}
        header_up X-Forwarded-Host {host}
    }
}
Enter fullscreen mode Exit fullscreen mode

Nginx equivalent: client_max_body_size 100M;, proxy_set_header X-Forwarded-Proto $scheme;, proxy_set_header Host $host;, and proxy_pass http://127.0.0.1:8000;. Paperless does not require WebSocket upgrades for normal use; the API and UI are HTTP. If you use the live document consumer status, keep proxy buffering off for /api/.

First-run hardening:

  1. Log in as the admin user from .env. The password is set on first boot; change it in the UI afterward and remove PAPERLESS_ADMIN_PASSWORD from .env.
  2. Create a non-admin account for daily use. Keep admin for settings only.
  3. Restrict signups. Paperless has no open registration by default; do not add users you do not need.
  4. If you test without a domain, SSH-tunnel to the loopback port: ssh -L 8000:127.0.0.1:8000 user@host, then open http://localhost:8000. Do not change the bind to 0.0.0.0 on a public VPS.

Updating, backups, and common pitfalls

Update by pulling the new image and recreating containers. Migrations run automatically on start.

cd ~/paperless-ngx
docker compose pull
docker compose up -d
docker compose logs -f webserver
Enter fullscreen mode Exit fullscreen mode

Back up the database and media together. A database dump alone is not enough; the original PDFs live in paperless_media.

cd ~/paperless-ngx
docker compose exec -T db pg_dump -U paperless paperless > paperless-db-$(date +%F).sql
docker run --rm -v paperless-ngx_paperless_media:/media -v "$PWD":/backup alpine tar czf /backup/paperless-media-$(date +%F).tar.gz -C /media .
Enter fullscreen mode Exit fullscreen mode

Restore by loading the SQL dump into a fresh db container and extracting the media tarball into the paperless_media volume before starting webserver and worker.

Two pitfalls from the docs and real deployments:

  • UID/GID mismatch. If USERMAP_UID/USERMAP_GID do not match the owner of the volumes, the consumer cannot write to media and documents stay in the queue. Check docker compose logs worker for permission errors and align the values in .env.
  • Wrong PAPERLESS_URL. A trailing slash, http instead of https, or a different hostname breaks login redirects and API links. Fix .env, then docker compose up -d to recreate both webserver and worker so they pick up the change.

Measured in our sandbox run: total memory 654.2 MB (sum of per-container peaks over a 30s idle window after startup) across 3 containers; largest container 615.3 MB; published port(s) 8000; HTTP probe returned 302. The run took 110.8s with the image already cached; a fresh server also has to download it. Required secret(s) PAPERLESS_ADMIN_PASSWORD, PAPERLESS_SECRET_KEY, POSTGRES_PASSWORD were generated for the test run, as the tutorial instructs. Container breakdown: webserver 615.3 MB, db 30.6 MB, broker 8.3 MB.


Verification: we ran this docker-compose stack in a disposable Docker environment and recorded the measurements above. They describe that run, not a guarantee for your host.


Originally published with full interactive benchmark metrics and server sizing notes at https://vpsfolio.com/self-host-paperless-ngx-docker/.

Top comments (0)