通过 windows docker 文件设置 git

Setup git via windows docker file

我写Dockerfile是基于windowsnanoserver。我需要添加到这张图片 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 构建执行此行时,我收到以下错误消息:

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.

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

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

听起来您想基于具有 git?

的纳米服务器映像创建容器映像

巧克力是个好主意。

如果您能提供更广泛的目标背景,我可以进一步帮助您。

干杯:)

我已经通过使用 MinGit 并将有关 mingit 的信息放入 environment/path 变量中解决了 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

您可以下载并使用 Git 拇指驱动器版本: https://git-scm.com/download/win

下寻找link

Git 用于 Windows 便携式 ("thumbdrive edition")

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

调用git.setup.exe安装文件,参数/?列出所有可能的开关。

要运行静默安装: git.setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS

要进行自定义安装:

运行 手动 git 使用参数 /SAVEINF="filename" 安装

例如:。 git-2.xx.exe /SAVEINF="filename"

然后使用 /LOADINF="filename"

重复安装

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

它记录在: Git: Silent-or-Unattended-Installation

根据@Mariusz 的回答,以下行将 git 安装到 Windows 图像

    # copy inf file
COPY resources/git-install.inf c:\git-install.inf
# get Git install file
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.30.1.windows.1/Git-2.30.1-64-bit.exe' -OutFile 'git.exe'; `
# install Git
    Start-Process "c:\git.exe" -ArgumentList '/SP-', '/VERYSILENT', '/NORESTART', '/NOCANCEL', '/CLOSEAPPLICATIONS', '/RESTARTAPPLICATIONS', '/LOADINF=git-install.inf' -Wait -NoNewWindow; `
# delete files
    Remove-Item -Force git-install.inf; `
    Remove-Item -Force git.exe;

根据这张图片,使用 Chocolatey 安装到 docker 图像对我有用:ehong

我将这些行添加到我的 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