Setup git via windows docker file

10,384

Solution 1

I've solved issue with GUI through usage of MinGit and by putting information about mingit into environment/path variable. I've used following approach:

RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/MinGit-2.12.2.2-64-bit.zip' -OutFile MinGit.zip

RUN Expand-Archive c:\MinGit.zip -DestinationPath c:\MinGit; \
$env:PATH = $env:PATH + ';C:\MinGit\cmd\;C:\MinGit\cmd'; \
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name Path -Value $env:PATH

Solution 2

You are correct, both Windows and Linux containers generally focus on running headless applications (i.e. without GUI).

It sounds like you want to create a container image based on the nanoserver image that has git?

Chocolatey is a great idea.

If you give me the broader context of your goals I can help you further.

Cheers :)

Solution 3

Installing to the docker image using Chocolatey worked for me as per this image: ehong

I addeded these lines to my Dockerfile:

ENV ChocolateyUseWindowsCompression false 
RUN powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
RUN choco install git.install -y --no-progress
Share:
10,384
Yuriy Zaletskyy
Author by

Yuriy Zaletskyy

Currently I work for company Kensium Solutions ( kensium.com ) in the position of Technical Lead. Specializing in developing solutions within the Acumatica Framework. Besides that I help fellow team members in solving tricky technical issues as well as improving performance in bottleneck situations.

Updated on June 05, 2022

Comments

  • Yuriy Zaletskyy
    Yuriy Zaletskyy almost 2 years

    I write Dockerfile which is based on windowsnanoserver. I need to add to this image git. In order to achieve it I did the following:

    RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/Git-2.12.2.2-64-bit.exe'
    RUN Invoke-Expression "c:\Git-2.12.2.2-64-bit.exe"
    

    But when I execute this lines via docker build, I receive following error message:

    Invoke-Expression : The term 'c:\Git-2.12.2.2-64-bit.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    I realize that this error message indicates that due to console nature of windows docker images I'll not be able to execute GUI installers. Unfortunately git doesn't have console installer. Chocolatey works fine under windowsservercore image but doesn't work at windowsnanoserver. In order to install git for windowsnanoserver I have idea to repeat in Dockerfile commands from chocolatey git installer which is fine for me, but still I'd like to know is there any simpler way to install git on windowsnanoserver?