通过windows docker文件设置git

问题描述 投票:0回答:2

我写的是基于Dockerfilewindowsnanoserver。我需要添加到这个图像git。为了实现它,我做了以下事情:

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"

但是,当我通过docker build执行此行时,收到以下错误消息:

Invoke-Expression:术语“c:\ Git-2.12.2.2-64-bit.exe”无法识别为cmdlet,函数,脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。

我意识到这个错误消息表明由于windows docker映像的控制台性质,我将无法执行GUI安装程序。不幸的是,git没有控制台安装程序。 Chocolateywindowsservercore图像下工作正常,但在windowsnanoserver不起作用。为了安装gaz for windowsnanoserver我有想法重复Dockerfile命令来自chocolatey git installer这对我来说很好,但我仍然想知道有没有更简单的方法在windowsnanoserver上安装git?

dockerfile docker-for-windows docker-desktop
2个回答
3
投票

你是对的,Windows和Linux容器通常都专注于运行无头应用程序(即没有GUI)。

听起来你想根据具有git的nanoserver图像创建一个容器图像?

Chocolatey是个好主意。

如果你给我更广泛的目标背景,我可以进一步帮助你。

干杯:)


2
投票

通过使用MinGit并将有关mingit的信息放入环境/路径变量,我已经解决了GUI的问题。我用过以下方法:

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
© www.soinside.com 2019 - 2024. All rights reserved.