用于Windows上的Matlab Compiler Runtime的Docker构build(非交互式安装)

我注意到在Docker构build中的一些步骤比在容器中手动执行相同的命令需要更多的时间。 为了提供一些上下文,安装Matlab Compiler Runtime(MCR)的过程如下:

  1. 从MathWorks网站下载MCR安装程序
  2. 解压安装文件
  3. 运行/bin/win64/setup.exe -mode silent -agreeToLicense yes( 非交互式安装

我创build了下面的Dockerfile来在包括dotnet-framework的Microsoft windowsservercore映像上设置MCR。

# Line 1: Use dotnet-framework base image FROM microsoft/dotnet-framework # Line 2: Download MCR installer (self-extracting executable) and save as ZIP file ADD https://www.mathworks.com/supportfiles/downloads/R2014b/deployment_files/R2014b/installers/win64/MCR_R2014b_win64_installer.exe C:\\MCR_R2014b_win64_installer.zip # Line 3: Use PowerShell SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] # Line 4: Unpack ZIP contents to installation folder RUN Expand-Archive C:\\MCR_R2014b_win64_installer.zip -DestinationPath C:\\MCR_INSTALLER # Line 5: Run the setup command for a non-interactive installation of MCR RUN Start-Process C:\MCR_INSTALLER\bin\win64\setup.exe -ArgumentList '-mode silent', '-agreeToLicense yes' -Wait # Line 6: Remove ZIP and installation folder after setup is complete RUN Remove-Item -Force -Recurse C:\\MCR_INSTALLER, C:\\MCR_R2014b_win64_installer.zip 

我使用这个命令build立一个新的图像:

 docker build -t analytics/dotnet-mcr --no-cache --force-rm . 

MCR的安装速度非常慢,与在第4行停止相比,然后从基于随后的映像的容器中手动运行MCR设置(使用完全相同的PowerShell命令)…任何理由为什么需要额外的3-4通过基于Dockerfile的构build执行相同的步骤时分钟?

注意:最佳做法build议使用下载实用程序而不是使用ADD ,但由于我正在删除中间映像以及删除下载的安装程序和解压后的安装文件夹,因此我没有任何与映像大小有关的限制。 另外,我喜欢看到ADD命令更干净的下载进度条。

我很欣赏可能提出的任何改进/优化。

Docker使用图层。 根据它的文档,每个RUN命令都会创build一个图层。 在您的场景中,每个图层都将存储与RUN命令相关的数据,因此将MCR_R2014b_win64_installer.zip作为单独的步骤删除将会在以前的图层中产生额外的空间。 我会build议在可能的地方减less运行命令。

请检查回购更多的帮助。