Git 在 NanoServer 中不工作(在 Docker 中)

Git not working in NanoServer (in Docker)

我需要在 Nano Server 中安装 Git。在我的研究过程中,我发现 Nano Server 不能处理 MSI 文件,这就是为什么我认为我可以轻松地将它下载到另一个容器(Windows Server Core 在我的情况下)并移动 Git 到另一个容器(Nano Server 容器)(想法来自这里: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 挂起一段时间后出现以下错误:

The command 'cmd /S /C git version' returned a non-zero code: 3221225495 Bus error

我想ok了,就这么简单,我直接把dockerfile中的RUN git version和镜像构建成功后容器中的运行命令去掉,这样就可以了检查什么是实际错误。但是当我在附加容器中调用 git 时,它只会挂起几秒钟并且什么都不做(就像我没有输入任何命令一样)。有什么想法吗?

PS:我不想要 MinGit(尽管出于某种原因 MinGit 在 Nano Server 中工作)因为我使用 NPM,它会生成 git MinGit.

中不存在的命令(从 GitHub 下载特定提交)

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:zip"

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 .zsetup.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

首先,您不必 运行 GIt 进行 Windows 设置。

您也可以尝试解压缩便携式可提取存档 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%