Setup git via windows docker file

时间秒杀一切 提交于 2020-07-16 04:42:30

问题


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?


回答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



回答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 :)




回答3:


You can download and use the Git Thumbdrive edition: https://git-scm.com/download/win

look for the link under:

Git for Windows Portable ("thumbdrive edition")

E.G.: https://github.com/git-for-windows/git/releases/download/v2.23.0.windows.1/PortableGit-2.23.0-64-bit.7z.exe




回答4:


Call the git.setup.exe installation file with the parameters /? to list all possible switches.

To run a silent installation: git.setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS

To do a customized installation:

run manually git installation with the parameter /SAVEINF="filename"

e.g:. git-2.xx.exe /SAVEINF="filename"

And then to repeat the installation with /LOADINF="filename"

e.g.: git.setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /LOADINF="filename"

It's documented on: Git: Silent-or-Unattended-Installation



来源:https://stackoverflow.com/questions/43467847/setup-git-via-windows-docker-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!