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
- Same text layer as the pipe, in about the same time (13.2 s).
- I capped it at 2 CPUs. Without caps, OCRmyPDF uses every core, upstream says.
-
On Linux, upstream says add
--user "$(id -u):$(id -g)", or--user 0:0with rootless Docker. -
On Docker Desktop for Mac,
--userworked too. Docker Desktop maps files to the Mac user, so I could not see the problem.
Use the Alpine image, with a tag
| Image | amd64 | arm64 |
|---|---|---|
| ocrmypdf-alpine | 313.6 MB | 309.4 MB |
| ocrmypdf (Ubuntu) | 466.6 MB | 461.7 MB |
-
jbarlow83/ocrmypdfis an alias for the Ubuntu image. Upstream calls it deprecated, yet its table still says "use this image" if unsure. - Languages inside: chi_sim, deu, eng, fra, osd (orientation), por, spa.
-
It runs as user
app, uid 1000, in/data. -
latestwas rebuilt on Nov 22 and is not the v17.14.2 image. Pin the tag.
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
-
Without
--upgrade python3, it built on v17.13.0 and failed on v17.14.2: a file clash with a newpython3-ndbmpackage. That may change with the Alpine repo. - With
-l ita+engit found 1,844 words. - The apk layer is 70.1 MB, against 16.2 MB for Italian alone on v17.13.0.
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
-
A scan copied into ./input was done 13.5 s later, or
13.7 s with
OCR_USE_POLLING=1. Upstream says to poll on network shares. -
user:is there because the app user may not be able to write to ./output (upstream). Set your own ids. - Keep ./output out of ./input, or it exits (upstream).
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_ARCHIVEwithOCR_ARCHIVE_DIRECTORY(default /processed, so mount it too), orOCR_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 toocrmypdf.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
- Container Manager lists 117 models. Of the 98 in Synology's CPU table, 91 are x86_64 and 7 are armv8.
- The armv8 ones: DS124, DS223, DS223j, DS423, DS220j, DS420j, DS120j. DS223j and DS124 have 1 GB.
- Synology: Container Manager Project
- Container Manager release notes: DSM 7.2 and later, compose on the Project page.
- Synology: what CPU does my NAS have
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)
--skip-text: kept the old text, no OCR.-
--redo-ocr: new OCR, same text, same page images. -
--force-ocr: re-encoded the page images, 6.49 to 4.65 MB. - Which flag fits which file: OCRmyPDF "page already has text".
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 |
- Both Docker text layers hold the same 2,054 words. pdftotext reads 5 short pieces in another order. Cause not tested.
- The Mac ran at background priority, Docker on 2 CPUs in a VM, so their times do not compare.
What I did not test
- amd64. Every run was arm64, on Apple Silicon.
- A Linux host, rootless Docker, Podman, a NAS or Synology.
- The
latesttag, rebuilt Nov 22.
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
- OCRmyPDF docs: Docker, for 17.14.2
- OCRmyPDF docs: batch jobs and watched folders
- watcher.py, MIT. OCRmyPDF is MPL 2.0.
- jbarlow83/ocrmypdf-alpine on Docker Hub
- We make the Apify Actor, and none of the other tools here.
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.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.