0

I'm trying to make a Matlab/Windows/FMU Compatible docker container to run my works AzureDevops CI/CD Pipeline. But I'm having issues when I run a CI build job online. When it tries to run any matlab code, I get his error:

Error:

2020-12-10T14:55:08.0295754Z ##[debug]   cd('C:\azp\agent\_work\_temp'); command_3a2582de_1b59_40fc_8400_bb6ddbb6b019
2020-12-10T14:55:08.0312327Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\azp\agent\_work\_tasks\RunMATLABCommand_28fdff80-51b4-4b6e-83e1-cfcf3f3b25a6\0.3.7\bin\run_matlab_command.bat "cd('C:\azp\agent\_work\_temp'); command_3a2582de_1b59_40fc_8400_bb6ddbb6b019""
2020-12-10T14:55:08.8200355Z Fatal Internal Error: std::exception: Bundle#4 start failed: Loading C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl\libmwlmgrimpl.dllfailed with error: The specified module could not be found.

I have no problem running my CI/CD loop using my own computer as a self-hosted agent, but I'm having problem running matlab inside my container.

I have tried doing this: https://www.mathworks.com/matlabcentral/answers/384746-libmwlmgrimpl-dll-error-in-r2017b by adding directly the dlls, to my src project, pushing the code(with the dlls) to azure and forcing dlls to be loaded to my docker container. Didn't work. A bit more info, I don't have any executables. I have a build process generated from a matlab control project and I also have a testing process running simulink files inside of a matlab unit test class.

Any ideas?

Dockerfile:

# Indicates that the windowsservercore image will be used as the base image.
FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Metadata indicating an image maintainer.
LABEL maintainer="***@***.com"

# Define Work Directory
WORKDIR /azp
RUN mkdir C:\install

# Installing Packet Manager
RUN powershell -command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN powershell -command Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser; Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
# Installing Depedencies
RUN mkdir c:\tools\cygwin && cd c:\tools\cygwin && curl -Sso cygwinsetup.exe https://cygwin.com/setup-x86_64.exe && start /wait cygwinsetup -q --root C:\tools\cygwin -P dos2unix,make,perl,python27,python38,rsync,libxml2,pbzip2,mc -X --site http://ctm.crouchingtigerhiddenfruitbat.org/pub/cygwin/circa/64bit/2020/05/31/142136/
RUN setx PATH "%PATH%;C:\tools\cygwin\bin" /M
RUN powershell -command choco install -y git
RUN powershell -command choco install -y mingw 
RUN powershell -command choco install -y cmake 
RUN powershell -command choco install -y wget 
RUN powershell -command choco install -y ninja 
RUN powershell -command choco install -y python3 

# Verification Step
RUN choco -?
RUN path
RUN ls
RUN wget --help

# Fetch

#RUN wget -rH https://releases.linaro.org/components/toolchain/binaries/latest-6/arm-eabi/
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN python get-pip.py
# Transfert Self-Hosted Agent Script
COPY start.ps1 .
# Transfert Matlab Install & Licences
COPY _temp_matlab_R2017b_win64 C:\\install\\_temp_matlab_R2017b_win64
COPY MathWorks C:\\Users\\ContainerAdministrator\\Downloads\\MathWorks
COPY network.lic C:\\install
COPY matlab_license.dat C:\\install
COPY installer_input.txt C:\\install
# Transfert Modelon Install & Licences
COPY FMI_Toolbox-2.8-win.exe C:\\install
COPY fmi_license.lic C:\\install
RUN ls ..\install
#Install Matlab
#RUN powershell.exe -command \
#     Start-Job -ScriptBlock {C:\install\_temp_matlab_R2017b_win64\setup.exe -inputFile C:\install\installer_input.txt} -Name matlabInstallContainer ;\
#     Wait-Job -Name "matlabInstallContainer";\
#     Stop-Job -Name "matlabInstallContainer";
RUN powershell.exe -command \
  "&C:\install\_temp_matlab_R2017b_win64\setup.exe -inputFile C:\install\installer_input.txt | Out-Null"
#Install Modelon
RUN C:\install\FMI_Toolbox-2.8-win.exe /S /D=C:\Program Files (x86)\Modelon\FMI Toolbox 2.8
#RUN matlab -r "cd 'C:\Program Files (x86)\Modelon\FMI Toolbox 2.8';setup('C:\install\fmi_license.lic', true);exit;"
RUN mkdir C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Modelon\Licenses\Server
RUN cp C:\install\fmi_license.lic C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Modelon\Licenses\Server

# Sets a command or process that will run each time a container is run from the new image.
CMD powershell .\start.ps1
#CMD [ "cmd" ]

Update:

Still not working. I have installed Windows 2016 Container, but got same errors.

...\libmwlmgrimpl.dllfailed with error: The specified module could not be found.

I'm adding a object dump,maybe it can help some of you? I do see LIBEAY32.DLL inside of the dump, but I don't see SSLEAY32.DLL, is that normal? Ref: https://www.mathworks.com/matlabcentral/answers/375270-why-does-my-matlab-compiler-standalone-application-fail-to-start-with-a-the-operating-system-cannot

C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl>objdump -x libmwlmgrimpl.dll | grep "DLL Name"
        DLL Name: ddux.dll
        DLL Name: instlic_4a.dll
        DLL Name: jit_launcher.dll
        DLL Name: libmwi18n.dll
        DLL Name: libmwfl.dll
        DLL Name: libmwms.dll
        DLL Name: libmwservices.dll
        DLL Name: libmx.dll
        DLL Name: libut.dll
        DLL Name: mpath.dll
        DLL Name: mvm.dll
        DLL Name: mlutil.dll
        DLL Name: settingscore.dll
        DLL Name: webproxy.dll
        DLL Name: boost_date_time-vc140-mt-1_56.dll
        DLL Name: boost_filesystem-vc140-mt-1_56.dll
        DLL Name: boost_log-vc140-mt-1_56.dll
        DLL Name: boost_system-vc140-mt-1_56.dll
        DLL Name: boost_thread-vc140-mt-1_56.dll
        DLL Name: CppMicroServices3.dll
        DLL Name: ADVAPI32.dll
        DLL Name: COMCTL32.dll
        DLL Name: COMDLG32.dll
        DLL Name: NETAPI32.dll
        DLL Name: WS2_32.dll
        DLL Name: SHLWAPI.dll
        DLL Name: dhcpcsvc.DLL
        DLL Name: PocoFoundation64.dll
        DLL Name: PocoNet64.dll
        DLL Name: PocoNetSSL64.dll
        DLL Name: WININET.dll
        DLL Name: msi.dll
        DLL Name: CRYPT32.dll
        DLL Name: IPHLPAPI.DLL
        DLL Name: MAPI32.dll
        DLL Name: ole32.dll
        DLL Name: libsqlite3.dll
        DLL Name: tbb.dll
        DLL Name: xerces-c_3_1.dll
        DLL Name: KERNEL32.dll
        DLL Name: USER32.dll
        DLL Name: SHELL32.dll
        DLL Name: OLEAUT32.dll
        DLL Name: MSVCP140.dll
        DLL Name: VCRUNTIME140.dll
        DLL Name: api-ms-win-crt-runtime-l1-1-0.dll
        DLL Name: api-ms-win-crt-stdio-l1-1-0.dll
        DLL Name: api-ms-win-crt-time-l1-1-0.dll
        DLL Name: api-ms-win-crt-convert-l1-1-0.dll
        DLL Name: api-ms-win-crt-heap-l1-1-0.dll
        DLL Name: api-ms-win-crt-environment-l1-1-0.dll
        DLL Name: api-ms-win-crt-locale-l1-1-0.dll
        DLL Name: api-ms-win-crt-string-l1-1-0.dll
        DLL Name: api-ms-win-crt-math-l1-1-0.dll
        DLL Name: api-ms-win-crt-utility-l1-1-0.dll
        DLL Name: api-ms-win-crt-filesystem-l1-1-0.dll
        DLL Name: LIBEAY32.dll

I'm also adding a working matlab/libmwlmgrimpl dependency walker analysis done on my work computer(self-hosted agent). I don't know how to do it via command line inside my docker container for comparison. Hope this help find with the missing module problem.

libmwlmgrimpl Dependency Analysis

Update#2:

After talking to Mathworks, using depency walker, dependencies.exe and vim diff, I found out that the windows 2016 server has LOT less dlls in it's system 32 folder than 'Windows 10' or the 'windows 2016 server with desktop experience'. Those dlls seem to be a must to make mathlab works, hence I needed to add them to my container. I copy pasted the Right difference of my main computer and the docker container to a folder in my docker container and added it to the path. Before, my previous error happened at second in 1 seconf after launching my MATLAB job. now I get a different error(which is PROGRESS!!) and fail at second 2 (which is PROGRESS!!).

Any of you have any idea about this new one?

##[debug]   cd('C:\azp\agent\_work\_temp'); command_35722346_1e7d_4546_956b_f1320bcc9adc
C:\Windows\system32\cmd.exe /D /S /C "C:\azp\agent\_work\_tasks\RunMATLABCommand_28fdff80-51b4-4b6e-83e1-cfcf3f3b25a6\0.3.7\bin\run_matlab_command.bat "cd('C:\azp\agent\_work\_temp'); command_35722346_1e7d_4546_956b_f1320bcc9adc""
Fatal Internal Error: std::exception: Bundle#4 start failed: Loading C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl\libmwlmgrimpl.dllfailed with error: %1 is not a valid Win32 application.

Weltgeist
  • 137
  • 1
  • 1
  • 11

2 Answers2

2

Matlab, Windows compatible Docker Container Fails to run Matlab job steps of Azure Devops CI/CD job

As I know, the MATLAB R2017b does not support Windows Server 2019 until MATLAB R2019a.

For MATLAB R2017b, you could try to use Windows Server 2016.

You could check the document System Requirements and Supported Compilers

enter image description here

So, you could try to use the image mcr.microsoft.com/windows:1809 or mcr.microsoft.com/windows/servercore:1607.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • I tried 1809,1607 and ltcs2016, with the same results. I had same error. Side effects: The only change is curl isn't installed in 2016 and cygwin doesn't work well on some of the version. https://stackoverflow.com/questions/43123851/unable-to-run-cygwin-in-windows-docker-container – Weltgeist Dec 15 '20 at 12:34
  • just adding I tried mcr.microsoft.com/windows/servercore:1809 initialy and not mcr.microsoft.com/windows:1809, I missread your answer. you were right it works well. – Weltgeist Jan 08 '21 at 18:39
1

As @Leo Liu-MSFT stated,

For MATLAB R2017b, you could try to use Windows Server 2016…⠀So, you could try to use the image mcr.microsoft.com/windows:1809 or mcr.microsoft.com/windows/servercore:1607.

To expand on that answer:

After contacting MathWorks, I understand that the Windows 2016 Server is a barebones version of Windows, with a minimalist set of System 32 DLLs. But MATLAB needs a lot of them to function. Hence, the solution was too either:

  1. Use a Windows 2016 Server with Desktop Experience (mcr.microsoft.com/windows:1809), or
  2. Use a Windows 2016 Server Docker Container (mcr.microsoft.com/windows/servercore:1809) and add all missing System32 DLLs. (Which can be found using dependency walker or making a Right Diff of the host and Docker container’s system32 folder)
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Weltgeist
  • 137
  • 1
  • 1
  • 11