我需要在Nano Server中安装Git。在研究过程中,我发现Nano Server无法使用MSI文件,这就是为什么我认为我可以轻松地将其下载到另一个容器(在我的情况下为Windows Server Core)并将Git的内容移动到另一个容器(Nano)服务器容器)(想法来自https://stefanscherer.github.io/how-to-build-nodejs-nanoserver-image/)。我尝试使用以下dockerfile:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN powershell Invoke-WebRequest -outfile gitsetup.exe https://github.com/git-for-windows/git/releases/download/v2.7.0.windows.1/Git-2.7.0-64-bit.exe
RUN setx /M Path "%Path%;c:\git\cmd;c:\git\bin;c:\git\usr\bin"
RUN powershell -command start-process .\gitsetup.exe -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES /CLOSEAPPLICATIONS /DIR=c:\git' -Wait
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.101-nanoserver-1909
USER ContainerAdministrator
RUN setx /M Path "%Path%;c:\git\cmd;c:\git\bin;c:\git\usr\bin"
COPY --from=0 "c:\git\cmd" "c:\git\cmd"
COPY --from=0 "c:\git\bin" "c:\git\bin"
COPY --from=0 "c:\git\usr\bin" "c:\git\usr\bin"
USER ContainerUser
RUN git version
但是当我尝试构建映像时,Step 12/14 : RUN git version
挂起一段时间后出现以下错误:
命令“ cmd / S / C git version”返回了非零代码: 3221225495总线错误
我认为好吧,这很简单,我只需从dockerfile中删除RUN git version
并在成功构建映像之后直接在容器中运行命令,以便我可以检查实际错误是什么。但是,当我在连接的容器中调用git时,它只是挂了几秒钟而没有执行任何操作(就像我没有键入任何命令一样)。有什么想法吗?
PS:我不希望使用MinGit(即使出于某种原因MinGit也可以在Nano Server上工作),因为我使用NPM,它会生成git命令(从GitHub下载特定提交),而该命令在MinGit中不存在。>
PS2:我无法将主容器更改为Windows Server Core,因为我将其与.NET Core和Windows容器一起使用。该SDK仅可用于Nano Server构建。
编辑:我尝试了@Voc的答案,它可以正常工作。对于任何想要确切代码dockerfile的人:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN setx /M Path "c:\git\cmd;c:\git\bin;c:\git\usr\bin;%Path%;c:\gcc\bin;c:\7zip"
RUN powershell -command Invoke-WebRequest -outfile portableGit.7z.exe https://github.com/git-for-windows/git/releases/download/v2.26.0.windows.1/PortableGit-2.26.0-64-bit.7z.exe
RUN powershell -command Invoke-WebRequest -UserAgent 'DockerCI' -outfile 7zsetup.exe http://www.7-zip.org/a/7z1514-x64.exe
RUN powershell -command start-process .\7zsetup.exe -ArgumentList '/S /D=c:/7zip' -Wait
RUN powershell 7z x portableGit.7z.exe -ogit
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.101-nanoserver-1909
USER ContainerAdministrator
RUN setx /M Path "C:\git\bin;C:\git\usr\bin;C:\git\mingw64\bin;C:\nodejs;%Path%"
COPY --from=0 "c:\git" "c:\git"
RUN git version
答案 0 :(得分:0)
首先,您不必运行Windows的GIt安装程序。
您还可以尝试在图像中所需的任何位置解压缩可移植的可提取存档PortableGit-2.26.0-64-bit.7z.exe
,然后将其添加到路径:
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%