近段时间会用得到ocr在其他项目中发现了这个Umi-ocr感觉还可以所以想起来了这个看看如何进行部署。主要是参照https://github.com/hiroi-sora/Umi-OCR_runtime_linux/blob/main/README-docker.md这个文档。并且尽量的使用国内的环境防止出现下载中断、更新过慢、Qt启动异常等问题。总体的目录结构只说关键文件其他不适用的不说Linux中容器化部署Umi-ocrDockerfile是主构建文件已修复了离线和镜像问题Dockerfile.ori是仅修复离线的构建文件1、项目下载文件Umi-OCR_Linux_Paddle_2.1.5.tar.xz地址如下https://github.com/hiroi-sora/Umi-OCR/releaseshttps://github.com/hiroi-sora/Umi-OCR_runtime_linux2、环境支撑下载文件https://github.com/hiroi-sora/Umi-OCR_runtime_linux3、改造过的Dockerfile添加了国内镜像并且修正了必须使用git的问题# Umi-OCR Docker# https://github.com/hiroi-sora/Umi-OCR# https://github.com/hiroi-sora/Umi-OCR_runtime_linuxFROM debian:11-slim ARGAPT_MIRRORhttp://mirrors.tuna.tsinghua.edu.cn/debian ARGAPT_SECURITY_MIRRORhttp://mirrors.tuna.tsinghua.edu.cn/debian-security LABELappUmi-OCR-PaddleLABELmaintainerhiroi-soraLABELversion2.1.5LABELdescriptionOCR software, free and offline.LABELlicenseMITLABELorg.opencontainers.image.sourcehttps://github.com/hiroi-sora/Umi-OCR_runtime_linux# 安装所需工具和 QT 依赖库# 可在构建时通过 --build-arg APT_MIRROR / APT_SECURITY_MIRROR 指定 Debian 镜像源。# 这里要求传入完整基础地址例如# http://mirrors.tuna.tsinghua.edu.cn/debian# http://mirrors.tuna.tsinghua.edu.cn/debian-security# 也支持传入 https 地址。构建时会先用 http 引导安装 ca-certificates再切回正式源。RUNAPT_MIRROR_CLEAN${APT_MIRROR%/}\APT_SECURITY_MIRROR_CLEAN${APT_SECURITY_MIRROR%/}\case${APT_MIRROR_CLEAN}in\https://*)APT_BOOTSTRAP_MIRRORhttp://${APT_MIRROR_CLEAN#https://};;\*)APT_BOOTSTRAP_MIRROR${APT_MIRROR_CLEAN};;\esac\case${APT_SECURITY_MIRROR_CLEAN}in\https://*)APT_BOOTSTRAP_SECURITY_MIRRORhttp://${APT_SECURITY_MIRROR_CLEAN#https://};;\*)APT_BOOTSTRAP_SECURITY_MIRROR${APT_SECURITY_MIRROR_CLEAN};;\esac\printfdeb %s bullseye main\n\ deb %s bullseye-security main\n\ deb %s bullseye-updates main\n\${APT_BOOTSTRAP_MIRROR}\${APT_BOOTSTRAP_SECURITY_MIRROR}\${APT_BOOTSTRAP_MIRROR}/etc/apt/sources.list\apt-getupdateapt-getinstall-y--no-install-recommends ca-certificates\printfdeb %s bullseye main\n\ deb %s bullseye-security main\n\ deb %s bullseye-updates main\n\${APT_MIRROR_CLEAN}\${APT_SECURITY_MIRROR_CLEAN}\${APT_MIRROR_CLEAN}/etc/apt/sources.list\apt-getupdateapt-getinstall-y--no-install-recommends\xz-utils ttf-wqy-microhei xvfb\libglib2.0-0 libgssapi-krb5-2 libgl1-mesa-glx libfontconfig1\libfreetype6 libxcb-icccm4 libxcb-image0 libxcb-keysyms1\libxcb-render-util0 libxcb-render0 libxcb-shape0 libxcb-xkb1\libxcb-xinerama0 libxkbcommon-x11-0 libxkbcommon0 libdbus-1-3\rm-rf/var/lib/apt/lists/*# 工作目录WORKDIR /app# 将离线包和本地运行脚本复制到构建上下文中。COPY Umi-OCR_Linux_Paddle_2.1.5.tar.xz /tmp/ COPY umi-ocr.sh /app/umi-ocr.sh COPY main_linux.py /tmp/main_linux.py# 解压离线发行包并写入 Linux 运行时入口和预配置项。RUNtar-xf/tmp/Umi-OCR_Linux_Paddle_2.1.5.tar.xz-C/tmp\cp-a/tmp/Umi-OCR_Linux_Paddle_2.1.5/. /app/\cp/tmp/main_linux.py /app/UmiOCR-data/main_linux.py\chmodx /app/umi-ocr.sh\printf\ [Global]\n\ server.host0.0.0.0\n\ ui.fontFamilyWenQuanYi Micro Hei\n\ ui.dataFontFamilyWenQuanYi Micro Hei\n\ /app/UmiOCR-data/.settings\rm-rf/tmp/Umi-OCR_Linux_Paddle_2.1.5 /tmp/Umi-OCR_Linux_Paddle_2.1.5.tar.xz /tmp/main_linux.py# 运行指令ENTRYPOINT[/app/umi-ocr.sh]4、仅修正了不再访问github的问题Dockerfile.ori# Umi-OCR Docker# https://github.com/hiroi-sora/Umi-OCR# https://github.com/hiroi-sora/Umi-OCR_runtime_linuxFROM debian:11-slim LABELappUmi-OCR-PaddleLABELmaintainerhiroi-soraLABELversion2.1.5LABELdescriptionOCR software, free and offline.LABELlicenseMITLABELorg.opencontainers.image.sourcehttps://github.com/hiroi-sora/Umi-OCR_runtime_linux# 安装所需工具和 QT 依赖库# 注意这里仍然需要访问 Debian 软件源应用本体本身已改为离线导入。RUNapt-getupdateapt-getinstall-y\xz-utils ttf-wqy-microhei xvfb\libglib2.0-0 libgssapi-krb5-2 libgl1-mesa-glx libfontconfig1\libfreetype6 libxcb-icccm4 libxcb-image0 libxcb-keysyms1\libxcb-render-util0 libxcb-render0 libxcb-shape0 libxcb-xkb1\libxcb-xinerama0 libxkbcommon-x11-0 libxkbcommon0 libdbus-1-3\rm-rf/var/lib/apt/lists/*# 工作目录WORKDIR /app# 将离线包和本地运行脚本复制到构建上下文中。COPY Umi-OCR_Linux_Paddle_2.1.5.tar.xz /tmp/ COPY umi-ocr.sh /app/umi-ocr.sh COPY main_linux.py /tmp/main_linux.py# 解压离线发行包并写入 Linux 运行时入口和预配置项。RUNtar-xf/tmp/Umi-OCR_Linux_Paddle_2.1.5.tar.xz-C/tmp\cp-a/tmp/Umi-OCR_Linux_Paddle_2.1.5/. /app/\cp/tmp/main_linux.py /app/UmiOCR-data/main_linux.py\chmodx /app/umi-ocr.sh\printf\ [Global]\n\ server.host0.0.0.0\n\ ui.fontFamilyWenQuanYi Micro Hei\n\ ui.dataFontFamilyWenQuanYi Micro Hei\n\ /app/UmiOCR-data/.settings\rm-rf/tmp/Umi-OCR_Linux_Paddle_2.1.5 /tmp/Umi-OCR_Linux_Paddle_2.1.5.tar.xz /tmp/main_linux.py# 运行指令ENTRYPOINT[/app/umi-ocr.sh]5、主启动文件其实是复制的umi-ocr.sh#!/bin/bashset-ecd$(dirname${BASH_SOURCE[0]})current_dir$(pwd)exportUMI_APP_PATH$(realpath${BASH_SOURCE[0]})if[-fUmiOCR-data/.embeddable/activate.sh];thencdUmiOCR-data/.embeddable../activate.shcd$current_direchoUse the Python embeddable environment.elif[-fUmiOCR-data/.venv/bin/activate];then.UmiOCR-data/.venv/bin/activateechoUse the Python virtual environment.elseechoUse the default Python environment.fiechopwd:$(pwd)if[${HEADLESS:-}true];thenechoUse headless mode.# In headless mode, prefer Qts offscreen backend so the app does not rely# on an X server and the xcb plugin chain inside the container.exportQT_QPA_PLATFORM${QT_QPA_PLATFORM:-offscreen}exportQT_QUICK_BACKEND${QT_QUICK_BACKEND:-software}exportLIBGL_ALWAYS_SOFTWARE${LIBGL_ALWAYS_SOFTWARE:-1}elseechoUse GUI mode.if[-z${DISPLAY:-}];thenechoError: \$DISPLAYis not set.exit1fifiexecpython3 UmiOCR-data/main_linux.py$6、linux中的docker入口main_linux.py Minimal Linux entrypointforUmi-OCRinDocker.importosimportsysimporttraceback def message_box(msg: str, type_: strerror)-int: prefixUmi-OCR Messageiftype_error:prefix[Error] Umi-OCR Erroreliftype_warning:prefix[Warning] Umi-OCR Warningprint(prefix,\n, msg)return0os.MessageBoxmessage_box def init_runtime_environment()-None: scriptos.path.abspath(__file__)os.chdir(os.path.dirname(script))if__name____main__:try: init_runtime_environment()except Exception: errtraceback.format_exc()message_box(Failed to initialize runtime environment.\n\n err)sys.exit(0)try: app_pathos.getenv(UMI_APP_PATH,)from py_src.runimportmain main(app_pathapp_path)except Exception: errtraceback.format_exc()message_box(Failed to start the main program.\n\n err)sys.exit(0)7、构建#普通构建dockerbuild-tumi-ocr-paddle.#无缓存构建dockerbuild --no-cache-tumi-ocr-paddle.8、无头启动这个也修正一些Qt启动问题#强制使用Qt offscreen平台及显式镜像dockerrun-d--nameumi-ocr\-eHEADLESStrue\-eQT_QPA_PLATFORMoffscreen\-eQT_QUICK_BACKENDsoftware\-eLIBGL_ALWAYS_SOFTWARE1\-p1224:1224\umi-ocr-paddle基本就OK了。9、再加一些文档,这是官方的https://umi-ocr.com/zh-CN