composebuilder

Docker Compose: Paperless-ngx with PostgreSQL and Redis

Run Paperless-ngx 2.20 document archive with PostgreSQL 16 and Redis in Docker Compose. OCR language setup, loopback-only port, backups and a consume folder.

When to use this stack

Paperless-ngx is a document management system. You scan or upload invoices, letters and contracts, it runs OCR on them, extracts searchable text, assigns tags and correspondents, and keeps the originals in a predictable folder structure. This stack runs Paperless-ngx 2.20.5 with PostgreSQL 16 as its database and Redis 7 as the task broker. The database and broker both have health checks, and the application starts only after they pass. The web interface is bound to 127.0.0.1, and the consume, export and media folders are named volumes, so a backup of the volumes covers the whole archive.

Use this stack when you have a steady flow of paper or PDF documents and want them searchable on your own server. Do not use it when you only archive a handful of files per year, because a folder of PDFs with good file names is simpler. Do not use it for documents that must be processed by a regulated system with its own audit trail, unless you also review the compliance requirements of that system. Paperless-ngx also needs a reasonable amount of CPU for OCR on large batches, so a very small single-board computer will process documents slowly, even though it runs the software.

docker-compose.yml

services:
  postgres:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

  paperless:
    image: ghcr.io/paperless-ngx/paperless-ngx:2.20.5
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      PAPERLESS_DBHOST: postgres
      PAPERLESS_DBNAME: ${POSTGRES_DB}
      PAPERLESS_DBUSER: ${POSTGRES_USER}
      PAPERLESS_DBPASS: ${POSTGRES_PASSWORD}
      PAPERLESS_REDIS: redis://redis:6379
      PAPERLESS_SECRET_KEY: ${PAPERLESS_SECRET_KEY}
      PAPERLESS_URL: ${PAPERLESS_URL}
      PAPERLESS_ADMIN_USER: ${PAPERLESS_ADMIN_USER}
      PAPERLESS_ADMIN_PASSWORD: ${PAPERLESS_ADMIN_PASSWORD}
      PAPERLESS_TIME_ZONE: ${PAPERLESS_TIME_ZONE}
      PAPERLESS_OCR_LANGUAGE: ${PAPERLESS_OCR_LANGUAGE}
    ports:
      - "127.0.0.1:8000:8000"
    volumes:
      - paperless_data:/usr/src/paperless/data
      - paperless_media:/usr/src/paperless/media
      - paperless_consume:/usr/src/paperless/consume
      - paperless_export:/usr/src/paperless/export

volumes:
  postgres_data:
  redis_data:
  paperless_data:
  paperless_media:
  paperless_consume:
  paperless_export:

.env

.env
POSTGRES_DB=paperless
POSTGRES_USER=paperless
POSTGRES_PASSWORD=CHANGE_ME_DB_PASSWORD
PAPERLESS_SECRET_KEY=CHANGE_ME_LONG_RANDOM_SECRET_KEY
PAPERLESS_URL=https://docs.example.com
PAPERLESS_ADMIN_USER=admin
PAPERLESS_ADMIN_PASSWORD=CHANGE_ME_ADMIN_PASSWORD
PAPERLESS_TIME_ZONE=Europe/Madrid
PAPERLESS_OCR_LANGUAGE=eng

Start and verify

Shell
# 1. Validate the compose file and the variable substitution
docker compose config --quiet

# 2. Start the stack in the background
docker compose up -d

# 3. postgres and redis should show "(healthy)", paperless should show "Up"
docker compose ps

# 4. Follow the startup log until the web server reports that it is running
docker compose logs -f paperless

# 5. Login page through the loopback port (expected: 200)
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:8000/accounts/login/

# 6. Drop a test PDF into the consume folder and check that it is imported
docker compose cp ./test.pdf paperless:/usr/src/paperless/consume/test.pdf
docker compose logs --tail=20 paperless

Sign in with the administrator account from .env. Changing PAPERLESS_ADMIN_PASSWORD in .env later does not change an account that already exists, so change the password inside the web interface after the first login.

Production checklist

  • Set PAPERLESS_URL to the public HTTPS address and place a reverse proxy in front of port 8000, so that links and CSRF checks work.
  • Use a long, random PAPERLESS_SECRET_KEY and keep it. Changing it signs out every user and breaks some stored tokens.
  • Keep postgres and redis unpublished. Only the paperless service should reach them.
  • Back up postgres_data and paperless_media at the same time. A database dump taken with pg_dump and the media volume together form a consistent archive.
  • Enable two-factor authentication for the administrator account in the web interface.
  • Limit who can write to the consume volume, because every file placed there is imported and processed.
  • Watch disk usage, since originals, thumbnails and the OCR text all take space, and plan for growth.
  • Pin the image tag and read the release notes before changing the major version, because schema migrations run at startup.

Common problems

  • Symptom: uploaded documents stay in the queue and never appear. Cause: the Redis broker is down or PAPERLESS_REDIS points to the wrong host. Fix: check docker compose ps, confirm the value is redis://redis:6379, and restart the stack.
  • Symptom: the log reports that a language is missing when OCR starts. Cause: PAPERLESS_OCR_LANGUAGE lists a language whose Tesseract data is not installed in the image. Fix: use a language the image provides, or extend the image with the Tesseract language package as described in the Paperless-ngx documentation.
  • Symptom: the web interface logs CSRF verification failed when you log in through the domain. Cause: PAPERLESS_URL does not match the address in the browser. Fix: set PAPERLESS_URL to the exact public address, including https, and recreate the container.
  • Symptom: the database container restarts and paperless cannot connect. Cause: the postgres data volume was created with other credentials. Fix: make POSTGRES_USER and POSTGRES_PASSWORD match the original values, or create a new volume on a fresh installation.
  • Symptom: files copied into the consume folder are ignored. Cause: the copy was made with the wrong owner or the file was still being written when the watcher read it. Fix: copy the file completely first, then move it into the folder, and check the log for import errors.

Variations

  • Several OCR languages: join language codes with a plus sign, for example eng+spa, and extend the image with the matching Tesseract packages as described in the documentation. Start with one language and add others only when you need them.
  • SQLite for a small archive: remove the postgres service and the PAPERLESS_DB* variables. Paperless-ngx then stores its data in SQLite inside the data volume, which is acceptable for a single user with a small document count.
  • Email import: configure the mail consumption settings in the web interface or through the documented environment variables, and keep the mailbox credentials out of the compose file.

Questions

How do documents get into Paperless-ngx?

You can upload them in the web interface, or copy files into the consume folder. Paperless-ngx watches that folder, runs OCR on each new file, indexes its text and stores the original in the media volume.

Why does Paperless-ngx need Redis?

Redis is the message broker for background tasks such as OCR, indexing and thumbnail generation. Without it, the web interface cannot queue document processing and new uploads stay unprocessed.

Which OCR language should I set?

Set PAPERLESS_OCR_LANGUAGE to the language of most of your documents, for example eng for English. Several languages can be combined with a plus sign, but each one must be installed in the image.

Adapt this stack

Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.

Open in builder
  • n8n Workflow Automation with PostgreSQL

    Self-host n8n 2.48 with PostgreSQL 16 in Docker Compose: encrypted credentials, database healthcheck, loopback-only port and a production checklist.

    • postgres
    • n8n
    Difficulty: Intermediate
  • Nextcloud + MariaDB + Redis File Sync

    Self-host Nextcloud with MariaDB 11.4 and Redis in Docker Compose. Pinned tags, database healthcheck, memory cache and the production steps for HTTPS and cron.

    • nextcloud
    • db
    • redis
    Difficulty: Intermediate
  • Home Assistant Smart Home Hub

    Run Home Assistant 2026.10 in Docker Compose with a pinned image, persistent config volume, timezone setup and reverse proxy notes for secure remote access.

    • homeassistant
    Difficulty: Intermediate
  • Ollama + Open WebUI Local AI Chat

    Run local AI models with Ollama and a chat interface with Open WebUI in Docker Compose. Pinned images, a health check, loopback-only access and RAM guidance.

    • ollama
    • open-webui
    Difficulty: Beginner

Browse more Automation, AI & Self-Hosted stacks or the full library.