本节介绍如何在 Docker 容器中运行 ABBYY FineReader Engine 12。此方案使用两个容器:
- 一个运行 ABBYY FineReader Engine 的容器
- 一个运行许可服务的容器
采用此方案可以提高容错能力,并确保所有容器持续运行。如果其中一个容器发生故障,您可以在不中断另一个容器的情况下将其重启。
此方案使用 Online License,该许可证会连接到 *.abbyy.com 许可证服务器。
ABBYY 许可服务同一时间只能使用一个 Online License。
无论 ABBYY 许可服务安装在何处,要使用 Online License,都需要满足以下条件:
- 互联网连接正常
- 允许通过 443 端口 (HTTPS) 连接到 *.abbyy.com
- GoDaddy Trusted Root Certification Authority
Certification Authority 的 GoDaddy 根证书应安装到本地计算机上的 Trusted Root Certification Authorities 证书存储中。有关该证书的详细信息,请参阅 GoDaddy 网站。
要在 Docker 容器中运行 ABBYY FineReader Engine 12:
- 在您的计算机上下载并安装 Docker for Windows。
- 启用 Windows 功能 Hyper-V 和 Containers。
- 在容器安装期间,选择“Use Windows containers instead of Linux containers”选项。
- 创建一个空目录,并将以下内容放入其中:
- docker-compose.yml — Docker Compose 配置文件 (请参见下文中的内容)
- TestAppFolder — 一个目录,其中包含
- Online License 令牌文件
- 已编译的测试应用程序,该程序使用此令牌文件、其密码以及您的 Customer Project ID
- Dockerfile_ls — 用于许可服务容器的 Dockerfile (请参见下文中的内容)
Dockerfile_ls 用于构建一个仅与一个由 Dockerfile_worker 构建的容器配合工作的容器。请勿将多个 ABBYY FineReader Engine 容器副本配置为与同一个许可服务配合工作。
- LicensingSettings_ls.xml - 包含许可服务许可参数的文件 (请参见下文中的内容)
- DeployLS.ps1 — 用于启动许可服务的脚本 (请参见下文中的内容)
注意:此脚本使用 /standalone 键运行许可服务。使用此键时,许可服务会作为前台进程运行,这是在 Docker 容器中运行服务的最佳实践。
- Dockerfile_worker — 用于构建包含 ABBYY FineReader Engine 和测试应用程序的容器的 Dockerfile (请参见下文中的清单)
- LicensingSettings_worker.xml - 包含 ABBYY FineReader Engine Library 许可参数的文件 (请参见下文中的清单)
- SetUpWorkerLicensing.ps1 - 用于将 LicensingSettings_worker.xml 中的服务器名称替换为 docker-compose.yml 中指定名称的脚本 (请参见下文中的清单)
- RunTestApp.ps1 — 用于运行测试应用程序的命令行脚本 (请参见下文中的清单)
- 使用以下命令将 ABBYY FineReader Engine 发行包解压到之前创建的目录中:
installRnt64.exe /extract InstallDir="<your_directory>/FRE"
- 要构建并运行这些容器,请使用以下命令:
运行测试应用程序的结果将在控制台中显示。
如果您使用 Windows Server Core 作为容器基础映像,则在部署 ABBYY FineReader Engine 后设置字体,如 使用字体 中所述。
version: '3'
services:
ls:
build:
context: .
dockerfile: Dockerfile_ls
hostname: servername
networks:
frenet:
aliases:
- servername
restart: on-failure
worker:
build:
context: .
dockerfile: Dockerfile_worker
args:
- service_address=servername
depends_on:
- ls
networks:
frenet:
restart: on-failure
networks:
frenet:
Dockerfile_ls# 复制许可服务
FROM mcr.microsoft.com/windows/servercore:ltsc2019 as fre12_ls
WORKDIR /app
ADD ./FRE/Licensing /app/FRE_Licensing
ADD ./LicensingSettings_ls.xml /app/FRE_Licensing/LicensingSettings.xml
WORKDIR /app/FRE_Licensing
# 安装许可服务
COPY ./DeployLS.ps1 /app/DeployLS.ps1
EXPOSE 3022
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENTRYPOINT /app/DeployLS.ps1
LicensingSettings_ls.xml<?xml version="1.0" encoding="utf-8"?>
<LicensingSettings xmlns="http://www.abbyy.com/Protection/LicensingSettings">
<LocalLicenseServer>
<ConnectionProtocol ProtocolType="TCP/IP" />
</LocalLicenseServer>
</LicensingSettings>
echo "Preparing logging folder:"
$folder = "C:\ProgramData\ABBYY\SDK\12\Licenses"
echo $folder
if( (Test-Path -Path $folder) -ne $True ) {
New-Item -Path $folder -ItemType Directory
}
echo "LicensingSettings.xml found:"
cd "C:/app/FRE_Licensing"
type LicensingSettings.xml
echo "Starting license service..."
.\LicensingService.exe /standalone
echo "License service stopped."
return 500
Dockerfile_workerFROM mcr.microsoft.com/windows/servercore:ltsc2019 as fre12installation
# 将提取的库复制到文件夹 C:/app/FRE12
ARG library_src="./FRE/FineReader Engine"
ADD $library_src /app/FRE12
ADD ./LicensingSettings_worker.xml /app/FRE12/Bin64/LicensingSettings.xml
# 替换 worker LicensingSetting.xml 中的 <service_address>
ARG service_address
COPY ./SetUpWorkerLicensing.ps1 /app/SetUpWorkerLicensing.ps1
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN /app/SetUpWorkerLicensing.ps1 -ServerAddress $service_address
# 复制并运行测试应用程序
COPY ./TestAppFolder /app/TestAppFolder
COPY ./RunTestApp.ps1 /app/RunTestApp.ps1
CMD /app/RunTestApp.ps1
LicensingSettings_worker.xml
LicensingSettings_worker.xml<?xml version="1.0" encoding="utf-8"?>
<LicensingSettings xmlns="http://www.abbyy.com/Protection/LicensingSettings">
<LicensingServers>
<MainNetworkLicenseServer ServerAddress="<server_address>" ProtocolType="TCP/IP" />
</LicensingServers>
</LicensingSettings>
Param (
[string]$service_address
)
# 用于准备客户端许可证日志文件夹并将 ServerAddress 写入 LicesingSettings.xml 的脚本
echo "正在准备日志文件夹:"
echo "C:\ProgramData\ABBYY\SDK\12\Licenses"
New-Item -Path "C:\ProgramData\ABBYY\SDK\12\Licenses" -ItemType Directory
echo "已找到 LicensingSettings.xml:"
cd "C:/app/FRE12/Bin64"
type LicensingSettings.xml
echo "正在将服务地址设置为:"
echo $service_address
((Get-Content -path LicensingSettings.xml -Raw) -replace '<server_address>',$Env:service_address) `
| Set-Content -Path LicensingSettings.xml
echo "LicensingSettings.xml 已完成设置:"
type LicensingSettings.xml
# 用于从 TestAppFolder 文件夹运行测试应用程序的脚本
# 使用参数启动测试应用程序(以 CommandLineInterface.exe 作为测试应用程序)
cd C:\app\TestAppFolder
.\CommandLineInterface.exe -pi -if Demo.tif -f PDF -of Demo.pdf
# 若要在 Docker container 中使用 CommandLineInterface 代码示例,需要执行以下操作:
# 1) 在 SamplesConfig.h 中为 Docker container 指定以下数据:
# - GetLicensePath、GetCustomerProjectId、GetLicensePassword
# - L"C:\\app\\FRE12\\Bin64\\FREngine.dll" 作为 GetFreDllPath
# 2) 针对 x64 配置重新生成项目。
# 3) 将 CommandLineInterface.exe、*.ABBYY.ActivationToken 许可证文件
# 及演示图像(Demo.tif)复制到 \TestAppFolder 文件夹中。
在 Windows 上安装许可服务
许可
激活