Tech 4 min read

How to Successfully Build the NDLOCR Docker Image

Someone at work asked “does this even run?” and I thought “it’s just building the image and running it,” but it completely refused to work, and I nearly threw my Windows machine out the window.

To make sure that sad situation never happens again, I’m writing down the correct procedure for my environment.

Prerequisites

  • Docker Desktop must be installed
  • Docker Desktop must be launched with administrator privileges (it didn’t work properly otherwise)

Environment

ItemDetails
EditionWindows 11 Home
Processor13th Gen Intel Core i7-13700H (2.40 GHz)
Installed RAM32.0 GB
System type64-bit OS, x64-based processor
GPUNVIDIA GeForce RTX 4060 Laptop
NVIDIA driver576.02
CUDA12.9

NDLOCR Setup: Working Procedure

1. Choosing the Repository

Use the community-patched version (syoyo fork) instead of the official (ndl-lab) one.

  • Repository URL: https://github.com/syoyo/ndlocr_cli.git
  • Reason: At the time, the official commit b844abf was attempting a Docker environment update. The author claimed it worked, but it didn’t work here at all. The syoyo fork has libraries adjusted for stability.

2. Getting the Code (Clone)

No submodules are used — the code is included directly (vendored). Standard procedure works.

  • Command:
    git clone https://github.com/syoyo/ndlocr_cli.git
    cd ndlocr_cli
  • Note: All code is in the src folder, so --recursive is not needed.

3. [Most Important] Modifying the Dockerfile

To avoid get-pip.py errors due to the end of Python 3.8 support, modify docker/Dockerfile at one location.

  • File to modify: docker/Dockerfile
  • Location: Around line 26
  • Change:
    • Wrong: wget https://bootstrap.pypa.io/get-pip.py
    • Correct: wget https://bootstrap.pypa.io/pip/3.8/get-pip.py
    • Add /pip/3.8 to the URL to specify the Python 3.8-specific script.

4. Running the Build

After the fix, create the image with the following command.

  • Command:
    docker build -t ocr-cli-py37:latest -f docker/Dockerfile .
    (The image name ocr-cli-py37 matches the log — any name is fine)

Background: Problems Encountered Along the Way

  1. “No submodules” issue:
    • The syoyo fork actually copies the code into the src folder, so submodule operations are unnecessary.
  2. “Official Dockerfile doesn’t work” issue:
    • The official version was in an unstable state from trying to migrate to a newer environment (CUDA 12, etc.), so the stable syoyo fork was used instead.
  3. “get-pip.py error” issue:
    • The latest get-pip.py stopped working in Python 3.8 environments, so the URL was changed to the version-specific one.
  4. “Build takes forever” issue:
    • The build takes quite a long time. Don’t interrupt it — just wait patiently.

After clearing all of these, the build completed successfully.


Modified Dockerfile

Here’s the full modified Dockerfile for copy-pasting.

FROM nvcr.io/nvidia/cuda:11.1.1-cudnn8-devel-ubuntu20.04

ENV PROJECT_DIR=/root/ocr_cli
ENV FORCE_CUDA="1"
ENV TORCH_CUDA_ARCH_LIST="7.5+PTX"
ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
ENV DEBIAN_FRONTEND=noninteractive

RUN set -x \
    && apt update \
    && apt upgrade -y

RUN set -x \
    && apt update \
    && apt -y install locales \
    && locale-gen ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL=ja_JP.UTF-8
RUN localedef -f UTF-8 -i ja_JP ja_JP.utf8

RUN set -x && apt -y install libgl1-mesa-dev libglib2.0-0 git
RUN set -x \
    && apt -y install python3.8 python3.8-dev \
    && ln -s /usr/bin/python3.8 /usr/bin/python \
    && apt -y install wget python3-distutils && wget https://bootstrap.pypa.io/pip/3.8/get-pip.py && python get-pip.py

COPY . ${PROJECT_DIR}

RUN set -x \
    && pip install -r ${PROJECT_DIR}/requirements.txt
RUN set -x && pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
RUN set -x && cd ${PROJECT_DIR}/src/ndl_layout/mmdetection && python setup.py bdist_wheel && pip install dist/*.whl
ENV PYTHONPATH $PYTHONPATH:${PROJECT_DIR}/src/text_recognition/deep-text-recognition-benchmark
RUN set -x && pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html

WORKDIR ${PROJECT_DIR}