OCRmyPDF in Docker: one command, tested

docker run --rm -i --cpus 2 \
  jbarlow83/ocrmypdf-alpine:v17.14.2 \
  --jobs 2 \
  - - < scan.pdf > out.pdf

1,838

of 1,955 words found in order, 10-page scan

13.9 s, PDF/A-2b, JPEGs kept byte for byte.

No Docker: Markdown, $0.006 a scanned page

Pipe the file, or mount a folder

The - - form reads the PDF from stdin and writes to stdout. Upstream recommends it: it "avoids file permission issues entirely".

For a folder, mount it at /data:

docker run --rm --cpus 2 \
  -v "$PWD:/data" -w /data \
  jbarlow83/ocrmypdf-alpine:v17.14.2 \
  --jobs 2 scan.pdf out.pdf

Use the Alpine image, with a tag

Compressed pull size, v17.14.2
Image amd64 arm64
ocrmypdf-alpine 313.6 MB 309.4 MB
ocrmypdf (Ubuntu) 466.6 MB 461.7 MB

A new language needed a python3 upgrade

Ask for a language the image lacks, and it stops with exit 3:

OCR engine does not have language data for the following requested languages:
ita

On Nov 23, this Dockerfile added Italian to v17.14.2:

FROM jbarlow83/ocrmypdf-alpine:v17.14.2
USER root
RUN apk add --no-cache --upgrade \
    python3 tesseract-ocr-data-ita
USER app
The exact apk error
ERROR: python3-ndbm-3.14.10-r2: trying to overwrite usr/lib/python3.14/lib-dynload/_dbm.cpython-314-aarch64-linux-musl.so owned by python3-3.14.10-r1.

The image has python3 3.14.10-r1. That night the repo had -r2, which moves this file into python3-ndbm.

Without USER root, apk fails too: the image runs as app.

Watched folder in compose: 13.5 s to output

This compose.yaml runs the image's own watcher.py:

services:
  ocrmypdf:
    image: jbarlow83/ocrmypdf-alpine:v17.14.2
    restart: unless-stopped
    user: "${PUID:-1000}:${PGID:-1000}"
    entrypoint: python3
    command: /app/watcher.py
    cpus: 2
    volumes:
      - "${SCAN_IN:-./input}:/input"
      - "${SCAN_OUT:-./output}:/output"
    environment:
      OCR_USE_POLLING: "${OCR_USE_POLLING:-0}"
      OCR_JSON_SETTINGS: '{"jobs": 2}'
      PYTHONUNBUFFERED: "1"
mkdir input output
docker compose up -d
Other settings watcher.py reads
  • Files already in ./input are skipped, per its source. Untested.
  • OCR_OUTPUT_STRUCTURE: FLAT, YEAR_MONTH or HIERARCHY.
  • OCR_ON_CONFLICT: SUFFIX (default), SKIP or OVERWRITE.
  • OCR_ON_SUCCESS_ARCHIVE with OCR_ARCHIVE_DIRECTORY (default /processed, so mount it too), or OCR_ON_SUCCESS_DELETE.
  • OCR_DESKEW, OCR_LOGLEVEL, OCR_PATTERNS, OCR_POLL_NEW_FILE_SECONDS, OCR_RETRIES_LOADING_FILE.
  • OCR_JSON_SETTINGS: a JSON string or file, passed to ocrmypdf.ocr(), like {"jobs": 2} above.

Synology: I have not tested it

Container Manager runs a compose file as a Project, on DSM 7.2 and later. The compose.yaml above is where I would start.

The image ships amd64 and arm64 only, and none of the 98 Container Manager models I matched to a CPU is 32-bit ARM. Upstream says its Synology script "only worked for x86-based Synology products", and notes their limited CPU and RAM.

Model counts and sources

Exit 6: the page already has text

Run it on a PDF that has text, and it stops:

PriorOcrFoundError: page 1 already has text! - aborting (use --force-ocr or --mode force to force OCR; see also help for --skip-text, --redo-ocr, and --mode)

v17.14.2: same words, 8 fewer in order

Run on the 10-page scan Words in order
Docker, v17.14.2 1,838
Docker, v17.13.0 1,846
Mac: OCRmyPDF 17.13.0, Tesseract 5.5.4 1,853

What I did not test

How I tested it
  • One Mac with Apple Silicon, Docker Desktop 4.94.0. Its Linux VM had 8 CPUs; each run got 2.
  • The scan: 10 proofread Wikisource book pages as 1920 px JPEGs, one 6.49 MB PDF.
  • Score: true words found in order, in pdftotext's reading of the result, out of 1,955.
  • One or two runs each, one at a time, with other work on the Mac. Treat the seconds as rough.
  • The image: OCRmyPDF 17.14.2, Tesseract 5.5.2, Ghostscript 10.08.0.
  • Scripts and results stay in our private repo, in research/bench/ocrmypdf-docker-2026-11-23/.
Sources

Questions people ask

Which OCRmyPDF Docker image should I use?

jbarlow83/ocrmypdf-alpine with a version tag, such as v17.14.2. Upstream calls it the recommended image. jbarlow83/ocrmypdf is an alias for the Ubuntu image, 153 MB bigger on amd64, and upstream says it will be removed.

How do I avoid file permission problems?

Pipe the file: docker run --rm -i, then - - < in.pdf > out.pdf. With a folder mount on Linux, upstream says add --user "$(id -u):$(id -g)", or --user 0:0 with rootless Docker. I tested only on a Mac.

How do I add a language to the OCRmyPDF Docker image?

Build a small image on top: USER root, apk add --no-cache tesseract-ocr-data-ita (your language code in place of ita), then USER app. On Nov 23, v17.14.2 also needed --upgrade python3 in that apk line.

Does OCRmyPDF in Docker run on a Synology NAS?

I have not tested it. Container Manager on DSM 7.2 or later takes a compose file as a Project, and the image ships for amd64 and arm64. Upstream's own Synology script only worked on x86 models.

Two ways to skip the work

Run it yourself. Our Apify Actor turns scanned PDFs and images into Markdown, tables included.

Try the Actor

Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.

Get one page free