![](/img/trans.png)
[英]Can't install pip packages inside a docker container with windows
[英]Can’t install Choclatey into windows docker container
我正在尝试将 Chocolatey 安装到 docker windows 容器中,在 Windows 10 机器上使用 Windows 容器而不是 linux 容器。 我在 PowerShell 控制台中运行 docker 构建命令,每次尝试使用以下行安装 Chocolatey: 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'))
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'))
它返回:
Exception calling "DownloadString" with "1" argument(s): "The remote name could not be resolved: 'chocolatey.org'"
At line:1 char:166
+ ... -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
它似乎无法解决 chocolatey.org 部分,我在构建命令中指定了 .network 卡:
docker build --network 21fb9a254e4b --progress=plain --tag jcontent/dockerwinbaseimage .
我还在 Daemon 文件中指定了 DNS 设置以查看 8.8.8.8 这是在测试它在此之前不起作用....
我附上了我的构建脚本。 任何帮助,将不胜感激。
# escape=`
FROM microsoft/dotnet-framework:4.7.2-sdk-windowsservercore-ltsc2016
FROM microsoft/windowsservercore:10.0.14393.1358
RUN @powershell [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
ENV chocolateyUseWindowsCompression=false
RUN @powershell 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 choco config set cachelocation C:\chococache
RUN choco feature enable --name allowGlobalConfirmation
RUN choco install git;
RUN choco install nodejs;
RUN choco install curl;
RUN choco install docker;
RUN choco install terraform;
# choco install visualstudio2015community --confirm --timeout 216000 \
RUN choco install dotnet4.6.1 --confirm --limit-output;
RUN choco install visualstudio2017enterprise --package-parameters "--passive --locale en-US --includeOptional" --confirm --limit-output --timeout 216000;
RUN choco install visualstudio2017-workload-azure --confirm --limit-output --timeout 21600 --package-parameters "--includeOptional";
RUN choco install visualstudio2017-workload-netcoretools --confirm --limit-output --timeout 21600 --package-parameters "--includeOptional";
RUN choco install visualstudio2017-workload-netweb --confirm --limit-output --timeout 21600 --package-parameters "--includeOptional";
# Destroy Choclotatey cache
RUN rmdir /S /Q C:\chococache
# common node tools
RUN npm install gulp -g && npm install grunt -g && npm install -g less && npm install phantomjs-prebuilt -g;
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Install .NET Core
ENV DOTNET_VERSION 3.1.7
ENV DOTNET_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/release/1.1.0/Binaries/$DOTNET_VERSION/dotnet-win-x64.$DOTNET_VERSION.zip
RUN Invoke-WebRequest $Env:DOTNET_DOWNLOAD_URL -OutFile dotnet.zip; \
RUN Expand-Archive dotnet.zip -DestinationPath $Env:ProgramFiles\dotnet -Force; \
RUN Remove-Item -Force dotnet.zip
# Install .NET Core
ENV DOTNET_VERSION 3.1.7
ENV DOTNET_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/preview/Binaries/$DOTNET_VERSION/dotnet-win-x64.$DOTNET_VERSION.zip
RUN Invoke-WebRequest $Env:DOTNET_DOWNLOAD_URL -OutFile dotnet.zip; \
RUN Expand-Archive dotnet.zip -DestinationPath $Env:ProgramFiles\dotnet -Force; \
RUN Remove-Item -Force dotnet.zip
# Install .NET Core SDK
ENV DOTNET_VERSION 3.1.7
ENV DOTNET_SDK_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-dev-win-x64.$DOTNET_SDK_VERSION.zip
RUN Invoke-WebRequest $Env:DOTNET_SDK_DOWNLOAD_URL -OutFile dotnet.zip; \
RUN Expand-Archive dotnet.zip -DestinationPath $Env:ProgramFiles\dotnet -Force; \
RUN Remove-Item -Force dotnet.zip
SHELL ["cmd", "/S", "/C"]
RUN setx /M PATH "%PATH%;%ProgramFiles%\dotnet"
# Trigger the population of the local package cache
ENV NUGET_XMLDOC_MODE skip
RUN mkdir C:\warmup \
RUN cd C:\warmup \
RUN dotnet new \
RUN cd .. \
RUN rmdir /S /Q C:\warmup
#Change Working Directory to Install DevOps Tools
WORKDIR /azp
#Install DevOps Agents
COPY start.ps1 .
#Configure DevOps Agent
CMD powershell .\start.ps1
我今天设法解决了这个令人沮丧的问题,这就是我在下一个人遇到这个问题时所做的,因为 Docker 不会很快解决它。
我所做的是在 Windows / Mac 上的桌面应用程序中,您可以编辑守护程序文件。 在 Docker 引擎下的 Docker 应用程序的设置下,我在文件底部的最后一个大括号上方添加了该行。 "dns": [ "Your DNS Address Here", "8.8.8.8" ]
然后,这允许您现在构建的所有 Docker 容器使用主机的 DNS 服务器。 从技术上讲,如果您可以访问: https://chocolatey.org/install.ps1 ,那么您应该能够访问 choco 存储库。
我还在https://github.com/jasric89/vsts-agent-docker/tree/master/windows/servercore/10.0.14393中构建了图像并在 repo 中标记了它:
微软/windowsservercore:10.0.14393.1358
然后我在我的第一个 Choco Install 命令之前设置: RUN choco feature enable --name allowGlobalConfirmation
,这使 choco 能够安装所有文件并且不会出错。
有了所有这些,我的 Docker 文件运行并构建了图像。 现在在我的测试环境中测试我的产品环境。 :)
对我有帮助的链接:
https://github.com/moby/moby/issues/24928 https://github.com/jasric89/vsts-agent-docker/blob/master/windows/servercore/10.0.14393/standard/VS2017/Dockerfile https: //docs.chocolatey.org/en-us/troubleshooting https://github.com/moby/moby/issues/25537
更新:
我在新版本中再次遇到了这个问题,在按照我自己的说明进行操作后,它并没有完全奏效。
经过几个小时的测试,我意识到 Windows 上的 Docker 使用 Hyper-V 网络设置。
在我的 Hyper V Switch Manager 中,我没有可以访问 Internet 的网络。 此外,当我尝试更改默认开关时,它不会让我这样做。 因此我不得不在 Hyper-V 网络中创建一个新网络。
然后我不得不编辑 docker 守护程序文件,在 Docker 设置中告诉它使用正确的网络,并且我还输入了我之前在我的 Anwser 中指定的 DNS 设置。
这是我完整的 docker 守护程序文件:
{ "registry-mirrors": [], "insecure-registries": [], "bridge": "Internet", "dns": [ "YOUR Local DNS Address Here", "8.8.8.8" ], "debug": false, "experimental": false }
感谢@jason 提供了一个很好的答案,它实际上帮助我解决了这个问题。 最后, Chocolatey 安装文档和一些其他在线资源的组合,我得到了这个工作:
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR /app
RUN 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 choco install dotnetcore-runtime --version 2.2.7 -y;
RUN choco install aspnetcore-runtimepackagestore --version 2.2.7 -y;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.