Microsoft Word 在 Docker 容器中调用其 COM 时崩溃

Microsoft Word crashes when invoking its COM inside Docker Container

我正在构建一个文档转换服务,需要:

该服务在 Windows 主机中运行良好(它使用 C# 中的 Office Interop),但我想将其容器化以简化 CI。

我知道 Microsoft explicitly discourages using Office server-side 但由于上述原因,这不是一个有效的答案。

这里是问题的最小简化重现。

我正在使用 Microsoft Office 使用此 Docker 文件创建一个 Docker 图像:

FROM microsoft/windowsservercore:10.0.14393.953

# Install Office deployment tool
ADD https://download.microsoft.com/download/2/7/A/27AF1BE6-DD20-4CB4-B154-EBAB8A7D4A7E/officedeploymenttool_8008-3601.exe C:/deploymenttool_autoextract.exe
RUN C:/deploymenttool_autoextract.exe /quiet /passive /extract:C:

# Install Office
RUN C:/setup.exe /configure configuration.xml

ENTRYPOINT powershell

构建镜像工作正常(这需要一段时间,但一切似乎都已正确安装):

PS C:\> docker build -t office2016 .
Sending build context to Docker daemon 9.513 MB
Step 1/5 : FROM microsoft/windowsservercore:10.0.14393.953
 ---> b4713e4d8bab
Step 2/5 : ADD https://download.microsoft.com/download/2/7/A/27AF1BE6-DD20-4CB4-B154-EBAB8A7D4A7E/officedeploymenttool_8008-3601.exe C:/deploymenttool_autoextract.exe
Downloading [==================================================>] 2.373 MB/2.373 MB
 ---> Using cache
 ---> 44646838dccb
Step 3/5 : RUN C:/deploymenttool_autoextract.exe /quiet /passive /extract:C:
 ---> Using cache
 ---> 34c29ed81a48
Step 4/5 : RUN C:/setup.exe /configure configuration.xml
 ---> Using cache
 ---> ffaff2d4c553
Step 5/5 : ENTRYPOINT powershell
 ---> Using cache
 ---> 3c0905d88e16
Successfully built 3c0905d88e16
PS C:\>

但是,使用 Office(特别是 word)失败了:

PS C:\> docker run -ti office2016

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\> $Word = New-Object -ComObject Word.Application
New-Object : Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005
Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
At line:1 char:9
+ $Word = New-Object -ComObject Word.Application
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

PS C:\>

我在事件日志中发现了这个 KERNELBASE.dll 崩溃:

PS C:\> Get-EventLog -LogName Application -After (Get-Date).AddMinutes(-1) | Format-Table -Wrap -AutoSize

Index Time         EntryType   Source                               InstanceID Message
----- ----         ---------   ------                               ---------- -------
  264 Mar 29 06:35 Information Windows Error Reporting                    1001 Fault bucket 108819405901, type 1
                                                                               Event Name: APPCRASH
                                                                               Response: Not available
                                                                               Cab Id: 0

                                                                               Problem signature:
                                                                               P1: WINWORD.EXE
                                                                               P2: 16.0.7870.2031
                                                                               P3: 58d7f952
                                                                               P4: KERNELBASE.dll
                                                                               P5: 10.0.14393.953
                                                                               P6: 58ba586d
                                                                               P7: c06d007e
                                                                               P8: 000da882
                                                                               P9:
                                                                               P10:

                                                                               Attached files:
                                                                               \?\C:\Windows\Temp\WER1F8D.tmp.csv
                                                                               \?\C:\Windows\Temp\WER1F8E.tmp.txt

                                                                               These files may be available here:
                                                                               C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_WINWORD.EXE_31f9c9
                                                                               d9099ee9f1dcb30a4d4769b8bed7fbe78_7d4a7f4a_08071f9d

                                                                               Analysis symbol:
                                                                               Rechecking for solution: 0
                                                                               Report Id: 39ac8782-7405-4d3d-acf6-401aeeedcfe7
                                                                               Report Status: 4104
                                                                               Hashed bucket: d26bd2875cf81eb545bb270d4c18672b
  263 Mar 29 06:35 Information Windows Error Reporting                    1001 Fault bucket , type 0
                                                                               Event Name: APPCRASH
                                                                               Response: Not available
                                                                               Cab Id: 0

                                                                               Problem signature:
                                                                               P1: WINWORD.EXE
                                                                               P2: 16.0.7870.2031
                                                                               P3: 58d7f952
                                                                               P4: KERNELBASE.dll
                                                                               P5: 10.0.14393.953
                                                                               P6: 58ba586d
                                                                               P7: c06d007e
                                                                               P8: 000da882
                                                                               P9:
                                                                               P10:

                                                                               Attached files:

                                                                               These files may be available here:
                                                                               C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_WINWORD.EXE_31f9c9d9
                                                                               099ee9f1dcb30a4d4769b8bed7fbe78_7d4a7f4a_182f1a5d

                                                                               Analysis symbol:
                                                                               Rechecking for solution: 0
                                                                               Report Id: 39ac8782-7405-4d3d-acf6-401aeeedcfe7
                                                                               Report Status: 4100
                                                                               Hashed bucket:
  262 Mar 29 06:35 Error       Application Error                          1000 Faulting application name: WINWORD.EXE, version: 16.0.7870.2031, time stamp:
                                                                               0x58d7f952
                                                                               Faulting module name: KERNELBASE.dll, version: 10.0.14393.953, time stamp:
                                                                               0x58ba586d
                                                                               Exception code: 0xc06d007e
                                                                               Fault offset: 0x000da882
                                                                               Faulting process id: 0x1714
                                                                               Faulting application start time: 0x01d2a8915664ac21
                                                                               Faulting application path: C:\Program Files (x86)\Microsoft
                                                                               Office\Root\Office16\WINWORD.EXE
                                                                               Faulting module path: C:\Windows\System32\KERNELBASE.dll
                                                                               Report Id: 39ac8782-7405-4d3d-acf6-401aeeedcfe7
                                                                               Faulting package full name:
                                                                               Faulting package-relative application ID:
  261 Mar 29 06:35 0           Software Protection Platform Service 1073742727 The Software Protection service has stopped.

  260 Mar 29 06:35 Information Software Protection Platform Service 1073758208 Successfully scheduled Software Protection service for re-start at
                                                                               2017-03-30T13:15:26Z. Reason: RulesEngine.


PS C:\>

我欢迎就如何解决此问题或以像素精确方式转换 Office 文档的任何其他方式提出建议,最好在 Docker 容器内。

额外信息

I am using Docker 1.13:

PS C:\build> docker version
Client:
 Version:      1.13.0
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Wed Jan 18 16:20:26 2017
 OS/Arch:      windows/amd64

Server:
 Version:      1.13.0
 API version:  1.25 (minimum version 1.24)
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Wed Jan 18 16:20:26 2017
 OS/Arch:      windows/amd64
 Experimental: false

这是崩溃的 Report.wer 文件:

Version=1
EventType=APPCRASH
EventTime=131352685691694832
ReportType=2
Consent=1
UploadTime=131352685700338868
ReportIdentifier=989281b5-1485-11e7-a710-eaddffe2c349
IntegratorReportIdentifier=269019fe-dcbd-435a-adc2-2420ed62b0ba
WOW64=1
NsAppName=WINWORD.EXE
AppSessionGuid=00001934-0018-000e-c921-465a92a8d201
TargetAppId=W:0000da39a3ee5e6b4b0d3255bfef95601890afd80709!0000da39a3ee5e6b4b0d3255bfef95601890afd80709!WINWORD.EXE
TargetAppVer=2017//03//26:17:24:34!1df35e!WINWORD.EXE
BootId=4294967295
Response.BucketId=d26bd2875cf81eb545bb270d4c18672b
Response.BucketTable=1
Response.LegacyBucketId=108819405901
Response.type=4
Response.CabId=107979656579
Sig[0].Name=Application Name
Sig[0].Value=WINWORD.EXE
Sig[1].Name=Application Version
Sig[1].Value=16.0.7870.2031
Sig[2].Name=Application Timestamp
Sig[2].Value=58d7f952
Sig[3].Name=Fault Module Name
Sig[3].Value=KERNELBASE.dll
Sig[4].Name=Fault Module Version
Sig[4].Value=10.0.14393.953
Sig[5].Name=Fault Module Timestamp
Sig[5].Value=58ba586d
Sig[6].Name=Exception Code
Sig[6].Value=c06d007e
Sig[7].Name=Exception Offset
Sig[7].Value=000da882
DynamicSig[1].Name=OS Version
DynamicSig[1].Value=10.0.14393.2.0.0.400.8
DynamicSig[2].Name=Locale ID
DynamicSig[2].Value=1033
DynamicSig[22].Name=Additional Information 1
DynamicSig[22].Value=2beb
DynamicSig[23].Name=Additional Information 2
DynamicSig[23].Value=2beba6fb4680d73a8c78ca7c24ccdb46
DynamicSig[24].Name=Additional Information 3
DynamicSig[24].Value=9cd2
DynamicSig[25].Name=Additional Information 4
DynamicSig[25].Value=9cd2e275ccb4247c4efe4926a99dfc92
UI[2]=C:\Program Files (x86)\Microsoft Office\Root\Office16\WINWORD.EXE
UI[5]=Check online for a solution (recommended)
UI[6]=Check for a solution later (recommended)
UI[7]=Close
UI[8]=Microsoft Word stopped working and was closed
UI[9]=A problem caused the application to stop working correctly. Windows will notify you if a solution is available.
UI[10]=&Close
LoadedModule[0]=C:\Program Files (x86)\Microsoft Office\Root\Office16\WINWORD.EXE
LoadedModule[1]=C:\Windows\SYSTEM32\ntdll.dll
LoadedModule[2]=C:\Windows\System32\KERNEL32.DLL
LoadedModule[3]=C:\Windows\System32\KERNELBASE.dll
LoadedModule[4]=C:\Windows\System32\ADVAPI32.dll
LoadedModule[5]=C:\Windows\System32\msvcrt.dll
LoadedModule[6]=C:\Windows\System32\sechost.dll
LoadedModule[7]=C:\Windows\System32\RPCRT4.dll
LoadedModule[8]=C:\Windows\System32\SspiCli.dll
LoadedModule[9]=C:\Windows\System32\CRYPTBASE.dll
LoadedModule[10]=C:\Windows\System32\bcryptPrimitives.dll
LoadedModule[11]=C:\Windows\System32\ucrtbase.dll
LoadedModule[12]=C:\Program Files (x86)\Microsoft Office\Root\Office16\AppVIsvSubsystems32.dll
LoadedModule[13]=C:\Windows\System32\USER32.dll
LoadedModule[14]=C:\Windows\System32\win32u.dll
LoadedModule[15]=C:\Windows\System32\GDI32.dll
LoadedModule[16]=C:\Windows\System32\gdi32full.dll
LoadedModule[17]=C:\Windows\System32\SHELL32.dll
LoadedModule[18]=C:\Windows\System32\cfgmgr32.dll
LoadedModule[19]=C:\Windows\System32\windows.storage.dll
LoadedModule[20]=C:\Windows\System32\combase.dll
LoadedModule[21]=C:\Windows\System32\powrprof.dll
LoadedModule[22]=C:\Windows\System32\shlwapi.dll
LoadedModule[23]=C:\Windows\System32\kernel.appcore.dll
LoadedModule[24]=C:\Windows\System32\shcore.dll
LoadedModule[25]=C:\Windows\System32\profapi.dll
LoadedModule[26]=C:\Windows\System32\ole32.dll
LoadedModule[27]=C:\Program Files (x86)\Microsoft Office\Root\Office16\VCRUNTIME140.dll
LoadedModule[28]=C:\Program Files (x86)\Microsoft Office\Root\Office16\AppVIsvStream32.dll
LoadedModule[29]=C:\Windows\SYSTEM32\USERENV.dll
LoadedModule[30]=C:\Program Files (x86)\Microsoft Office\Root\Office16\c2r32.dll
LoadedModule[31]=C:\Windows\System32\OLEAUT32.dll
LoadedModule[32]=C:\Windows\System32\msvcp_win.dll
LoadedModule[33]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso20win32client.dll
LoadedModule[34]=C:\Program Files (x86)\Microsoft Office\Root\Office16\MSVCP140.dll
LoadedModule[35]=C:\Program Files (x86)\Microsoft Office\Root\Office16\wwlib.dll
LoadedModule[36]=C:\Windows\SYSTEM32\d3d11.dll
LoadedModule[37]=C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.14393.953_none_baad48403594ab3f\gdiplus.dll
LoadedModule[38]=C:\Program Files (x86)\Microsoft Office\Root\Office16\oart.dll
LoadedModule[39]=C:\Windows\SYSTEM32\dxgi.dll
LoadedModule[40]=C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.14393.953_none_89c2555adb023171\COMCTL32.dll
LoadedModule[41]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso30win32client.dll
LoadedModule[42]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso40uiwin32client.dll
LoadedModule[43]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso50win32client.dll
LoadedModule[44]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso98win32client.dll
LoadedModule[45]=C:\Windows\SYSTEM32\WTSAPI32.dll
LoadedModule[46]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso99Lwin32client.dll
LoadedModule[47]=C:\Windows\SYSTEM32\MSIMG32.dll
LoadedModule[48]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso.dll
LoadedModule[49]=C:\Windows\SYSTEM32\msi.dll
LoadedModule[50]=C:\Windows\SYSTEM32\bcrypt.dll
LoadedModule[51]=C:\Windows\SYSTEM32\d2d1.dll
LoadedModule[52]=C:\Windows\SYSTEM32\CRYPT32.dll
LoadedModule[53]=C:\Windows\SYSTEM32\MSASN1.dll
LoadedModule[54]=C:\Windows\SYSTEM32\WINSTA.dll
LoadedModule[55]=C:\Windows\SYSTEM32\VERSION.dll
LoadedModule[56]=C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\MSPTLS.DLL
LoadedModule[57]=C:\Windows\SYSTEM32\d3d10warp.dll
State[0].Key=Transport.DoneStage1
State[0].Value=1
File[0].CabName=WERInternalMetadata.xml
File[0].Path=WERC595.tmp.WERInternalMetadata.xml
File[0].Flags=851970
File[0].Type=5
File[0].Original.Path=\?\C:\ProgramData\Microsoft\Windows\WER\Temp\WERC595.tmp.WERInternalMetadata.xml
File[1].CabName=triagedump.dmp
File[1].Path=triagedump.dmp
File[1].Flags=808255490
File[1].Type=6
File[2].CabName=WERGenerationLog.txt
File[2].Flags=851970
File[2].Type=5
File[2].Buffer=FFFE53006E0061007000730068006F0074002000640075006D007000650072002000640065006100630074006900760061007400650064002E000D000A002D002000200053006E0061007000730068006F007400200061007600610069006C00610062006C0065003A00200030002E000D000A002D002000200053006E0061007000730068006F00740073002000640069007300610062006C00650064003A002000300030002E000D000A002D002000200020002000200053006E0061007000730068006F00740020007300740061007400750073003A002000430030003000300030003000360031002E000D000A002D002000200020002000200020002000440075006D0070006500720020007300740061007400750073003A002000300030003000300030003000300031002E000D000A002D00200020002000500072006F0063006500730073002000570045005200200066006C006100670073003A002000300030003000300030003000300030002E000D000A002D00200057006100740073006F006E00200072006500710075006500730074002000640075006D0070003A002000300030003100300030003100410034002E000D000A000D000A0053006E0061007000730068006F0074002000640075006D007000650072002000640065006100630074006900760061007400650064002E000D000A002D002000200053006E0061007000730068006F007400200061007600610069006C00610062006C0065003A00200030002E000D000A002D002000200053006E0061007000730068006F00740073002000640069007300610062006C00650064003A002000300030002E000D000A002D002000200020002000200053006E0061007000730068006F00740020007300740061007400750073003A002000430030003000300030003000360031002E000D000A002D002000200020002000200020002000440075006D0070006500720020007300740061007400750073003A002000300030003000300030003000300031002E000D000A002D00200020002000500072006F0063006500730073002000570045005200200066006C006100670073003A002000300030003000300030003000300030002E000D000A002D00200057006100740073006F006E00200072006500710075006500730074002000640075006D0070003A002000300030003100300030003100410034002E000D000A000D000A00
File[3].CabName=memory.csv
File[3].Path=WERCE00.tmp.csv
File[3].Flags=851971
File[3].Type=5
File[3].Original.Path=\?\C:\Windows\Temp\WERCE00.tmp.csv
File[4].CabName=sysinfo.txt
File[4].Path=WERCE30.tmp.txt
File[4].Flags=851971
File[4].Type=5
File[4].Original.Path=\?\C:\Windows\Temp\WERCE30.tmp.txt
File[5].CabName=Report.cab
File[5].Path=Report.cab
File[5].Flags=196608
File[5].Type=11
File[5].Original.Path=\?\C:\Windows\system32\Report.cab
FriendlyEventName=Stopped working
ConsentKey=APPCRASH
AppName=Microsoft Word
AppPath=C:\Program Files (x86)\Microsoft Office\Root\Office16\WINWORD.EXE
NsPartner=windows
NsGroup=windows8
ApplicationIdentity=51EB66DF67BACB90D7BBEDF0AB950AC2
MetadataHash=497883896

我正在使用 Windows Server 2016 作为 Docker 主机:

PS C:\> [System.Environment]::OSVersion

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.14393.0 Microsoft Windows NT 10.0.14393.0

具体来说,我是运行这个流浪形象:https://atlas.hashicorp.com/StefanScherer/boxes/windows_2016_docker

最后,似乎至少有另一个人尝试用 Office 2013 做到这一点,但也没有成功。参见:

https://forums.docker.com/t/appcrash-kernelbase-dll-error-when-i-try-to-use-microsoft-office-in-docker-container/25706/10 更新了一个有效的解决方案。