powershell - Windows上用于Matlab编译器运行时的Docker构建(非交互式安装)

标签 powershell docker

我注意到,与在容器中手动执行相同命令相比,Docker构建中的某些步骤花费更多时间。为了提供一些上下文,安装Matlab编译器运行时(MCR)的过程如下:

  • 从MathWorks网站
  • 下载MCR安装程序
  • 解压安装文件
  • 运行/bin/win64/setup.exe -mode Silent -agreeToLicense是(非交互式安装)

  • 我创建了以下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
    

    我使用以下命令构建新图像:
    docker build -t analytics/dotnet-mcr --no-cache --force-rm .
    

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

    注意:最佳做法建议使用下载实用程序而不是ADD,但是由于我要删除中间镜像以及删除下载的安装程序和未打包的安装文件夹,因此我对镜像大小没有任何限制。另外,我喜欢看到ADD命令的更干净的下载进度栏。

    我感谢您提出的任何改进/优化。

    最佳答案

    Docker使用层。根据它documentation,每个 RUN 命令都会创建一个图层。在您的方案中,每个层将存储与 RUN 命令相关的数据,因此,作为单独的步骤删除MCR_R2014b_win64_installer.zip将在先前的层中造成额外的空间。我建议尽可能减少 RUN 命令。

    请检查repo以获取更多帮助。

    关于powershell - Windows上用于Matlab编译器运行时的Docker构建(非交互式安装),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45694235/

    相关文章:

    windows - 批处理变量被设置为 ■1 而不是预期的输出

    Powershell:当文件名包含字符 [ ] 时,移动项目不起作用

    excel - 使用 Powershell 确认提示

    Docker NodeJS bcrypt 错误

    docker - 使用常见的中间/最终步骤维护多个 docker 镜像

    go - 推荐的 Docker 项目结构

    powershell - 远程注销用户

    powershell - 如何知道远程工作站上是否安装了powershell?

    docker - 如何在docker容器中正确使用系统用户

    docker - 在 docker 的构建阶段使用 github 私有(private) repo 部署 key 进行 npm install