I need to install Git in Nano Server. During my research I saw that Nano Server can't work with MSI files and that's why that I thought I can easily download it in another container (Windows Server Core in my situation) and move the contents of Git to the other container (the Nano Server container) (Idea is from here: https://stefanscherer.github.io/how-to-build-nodejs-nanoserver-image/). I tried with the following 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
But when I try to build the image, I get the following error after the Step 12/14 : RUN git version
hangs for a while:
The command 'cmd /S /C git version' returned a non-zero code: 3221225495 Bus error
I thought ok, that's simple, I'll just remove the RUN git version
from the dockerfile and run the command directly in the container after the image has successfully been built, so that I can check what is the actual error. But when I call git in the attached container, it just hangs for a few seconds and does nothing (like I didn't type any command). Any ideas?
PS: I don't want MinGit (even though MinGit works in Nano Server for some reason) because I use NPM, which spawns git commands (to download a specific commit from GitHub) that do not exist in MinGit.
PS2: I can't change my main container to Windows Server Core, since I am using it with .NET Core and Windows Containers. The SDK is only available with a Nano Server build.
Edit: I tried @Voc's answer and it works. For anyone that wants the exact code 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
First, you don't have to run the GIt for Windows setup.
You could also try and uncompress the Portable extractable archive PortableGit-2.26.0-64-bit.7z.exe
anywhere you want in the image, and then add to the path:
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%