我注意到,Docker构建中的一些步骤比在容器中手动执行相同的命令花费更多的时间。为了提供一些上下文,安装(MCR)的过程如下:
我创建了以下Dockerfile,以便在包括dotnet框架在内的映像上设置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安装程序.当通过基于Dockerfile的构建执行相同的步骤时,为什么需要额外的3-4分钟呢?
注意:最佳实践建议使用下载实用程序而不是使用ADD,但是我没有任何与图像大小相关的限制,因为我要删除中间映像以及删除下载的安装程序和解压缩安装文件夹。另外,我喜欢看到ADD命令的更干净的下载进度条。
我赞赏可能提出的任何改进/优化。
https://stackoverflow.com/questions/45694235
复制相似问题