Windows上的慢速Docker运行步骤,为什么?

时间:2017-10-09 19:24:35

标签: docker windows-server-2016 docker-windows

我尝试使用以下dockerfile创建新的泊坞窗图片,但是花了很长时间才完成其中一个步骤:

FROM microsoft/dotnet-framework:4.7

SHELL ["powershell"]

# Note: Get MSBuild 12.
RUN Invoke-WebRequest "https://download.microsoft.com/download/9/B/B/9BB1309E-1A8F-4A47-A6C5-ECF76672A3B3/BuildTools_Full.exe" -OutFile "$env:TEMP\BuildTools_Full.exe" -UseBasicParsing
RUN &  "$env:TEMP\BuildTools_Full.exe" /Silent /Full
# Todo: delete the BuildTools_Full.exe file in this layer

# Note: Add .NET 
## RUN Install-WindowsFeature NET-Framework-45-Features ; \

# Note: Add NuGet
RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\windows\nuget.exe" -UseBasicParsing
WORKDIR "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0"

# Note: Add Msbuild to path
RUN setx PATH '%PATH%;C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\msbuild.exe'
CMD ["C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\msbuild.exe"]

以下是目前的输出:

PS C:\MyWorkspace\images\msbuild> docker build -t msbuild .
Sending build context to Docker daemon   2.56kB
Step 1/9 : FROM microsoft/dotnet-framework:4.7
 ---> 91abbfdc50cb
Step 2/9 : MAINTAINER mohamed.elkammar@gmail.com
 ---> Using cache
 ---> fbf720101007
Step 3/9 : SHELL powershell
 ---> Using cache
 ---> 642cf0e08730
Step 4/9 : RUN Invoke-WebRequest "https://download.microsoft.com/download/9/B/B/9BB1309E-1A8F-4A47-A6C5-ECF76672A3B3/BuildTools_Full.exe" -OutFile "$env:TEMP\BuildTools_Full.exe" -UseBasicParsing
 ---> Using cache
 ---> a722c88fee0f
Step 5/9 : RUN &  "$env:TEMP\BuildTools_Full.exe" /Silent /Full
 ---> Using cache
 ---> 4fda7448f2e4
Step 6/9 : RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\windows\nuget.exe" -UseBasicParsing
 ---> Running in eec036874574

此外,这是docker info的输出:

C:\Windows\system32>docker info
Containers: 2
 Running: 1
 Paused: 0
 Stopped: 1
Images: 5
Server Version: 17.06.1-ee-2
Storage Driver: windowsfilter
 Windows:
Logging Driver: json-file
Plugins:
 Volume: local
 Network: l2bridge l2tunnel nat null overlay transparent
 Log: awslogs etwlogs fluentd json-file logentries splunk syslog
Swarm: inactive
Default Isolation: process
Kernel Version: 10.0 14393 (14393.1715.amd64fre.rs1_release_inmarket.170906-1810)
Operating System: Windows Server 2016 Datacenter
OSType: windows
Architecture: x86_64
CPUs: 1
Total Memory: 4.75GiB
Name: instance-1
ID: B2BG:6AW5:Y32S:YLIO:FE25:WWDO:ZAGQ:CZ3M:S5XM:LSHB:U5GM:VYEM
Docker Root Dir: C:\ProgramData\docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

什么会导致简单的下载步骤永远消失?

2 个答案:

答案 0 :(得分:1)

我在Docker和Windows上也遇到过类似的问题。尝试了以下选项:

  1. 检查DNS是否太慢。我用8.8.8.8替换了/etc/resolve.conf中的几个名称服务器条目,并进行了强制重装。这有助于减少加载时间。

  2. 检查docker是否通过IPv6连接到dockerd;就我而言,这不是听众。在网络接口上禁用IPv6并重新启动计算机有助于减少加载时间。

答案 1 :(得分:0)

docker构建过程比运行容器要花费更长的时间。这也取决于docker是否已缓存。

因此,通常在没有缓存的情况下第一次构建容器时,它会花费最长的时间,然后后续的docker构建,Docker Engine将使用其缓存(如果可用)。当您运行容器时,一旦构建便更快。

尤其是在首次构建时,除非从Docker镜像中拉出副本并在本地可用,否则docker将从公共注册表中提取microsoft / dotnet-framework:4.7。如果是,则Docker Engine将使用它,否则,它将从远程存储库中将其放入。如果您有本地副本,则速度更快。您可以根据需要将其拉到构建之前,也可以将其放在本地私有注册表中,然后将标签更改为注册表URL。

哪一步确实很慢?最后一个获取nuget.exe的地方?如果是这样,首先想到的可能是名称解析,DNS,防火墙或到达互联网的网络超时。

尝试运行此容器以检查名称解析,并查看它能否快速获取该文件。

FROM centos

MAINTAINER Blake Russo

运行yum install -y dig wget bind-utils nc; dig -x dist.nuget.org; nslookup dist.nuget.org; wget dist.nuget.org/win-x86-commandline/latest/nuget.exe; ls -la nug *;

相关问题